didRegisterForRemoteNotificationsWithDeviceToken
にあるトークンをサーバーに送信しようとしています。しかし、送信中にエラーが発生しました:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (Foundation._SwiftNSData)
。リクエストの場合は、Alamofire
フレームワークを使用します。私のコードは:プッシュ通知のトークンをサーバーに送信します。 Alamofireエラー
func signUp(withToken token: Data, completion: (Error) -> Void) {
let parameters: Parameters = ["registration_id": token]
print("token = \(token)")
Alamofire.request(baseUrl + signUpPath, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON(completionHandler: {response in
})
}
Print
私を示していますtoken = 32 bytes
。助言がありますか?サーバに送信する前に、Data
タイプの追加ステップが必要なのでしょうか?
UPDATE
私はNSString
型にトークンを変換しようとしたが、nil
let tokenNSString: NSString? = NSString(data: token, encoding: String.Encoding.utf8.rawValue)
print("nsstrgin from token = \(tokenNSString)")
NSDataを文字列に変換し、サーバー(http://stackoverflow.com/questions/4994302/didregisterforremotenotificationswithdevicetoken-doesnt-invoke-on-calling-regi)に送信できます。サーバーにデータとして送信する場合は、multipartform upload(http://stackoverflow.com/questions/26121827/uploading-file-with-parameters-using-alamofire)を試してください。 – vishnuvarthan
@vishnuvarthan私の更新を見てください。 – RomanHouse
これを使用して文字列に変換します。 http://stackoverflow.com/questions/9372815/how-can-i-convert-my-device-token-nsdata-into-an-nsstring – vishnuvarthan