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
유형에 토큰을 변환하려고하지만이 deviceToken
프로젝트의 AppDelegate에 didRegisterForRemoteNotificationsWithDeviceToken
내부에 점점 것은 NSData
객체이다 nil
let tokenNSString: NSString? = NSString(data: token, encoding: String.Encoding.utf8.rawValue)
print("nsstrgin from token = \(tokenNSString)")
NSData를 String으로 변환하고 서버 (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