Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid parameter: Token Reason: iOS device tokens must be no more than 400 hexadecimal characters

I am trying to create platform endpoint in amazon sns from the console. Below is the device token which I received from FCM/APNs:

fUG5dIcN_pA:APA91bEciRwWuvTIezAKcJ5y1xz5z6BygE3YJkywdCGCFJD93NTfjARwPRommwgsfvVo2iH_qZWT7D2Lxnc69uanato1UUq-nLl5R1L0qF4exT7zjM9Wdy9Evs6h-EOBtIVv7Vv8bPE1

I am getting an error: iOS device tokens must be no more than 400 hexadecimal characters.looks like APNs has sent token in string format and Amazon is expecting it in hexadecimal chars.

like image 748
narendra Avatar asked Dec 15 '17 04:12

narendra


2 Answers

Try the below code in didRegisterForRemoteNotificationsWithDeviceToken:

let deviceToken = deviceToken.map {String(format:"%02.2hhx",$0)}.joined()
print(deviceToken)

And Paste the device token in amazon SNS console, it will work.

like image 138
Surya Avatar answered Sep 22 '22 12:09

Surya


For objective-c you can use this:

NSString * deviceTokenString = [[[[deviceToken description]
                         stringByReplacingOccurrencesOfString: @"<" withString: @""] 
                        stringByReplacingOccurrencesOfString: @">" withString: @""] 
                       stringByReplacingOccurrencesOfString: @" " withString: @""];

NSLog(@"The generated device token string is : %@",deviceTokenString);
like image 24
DionizB Avatar answered Sep 22 '22 12:09

DionizB