0
votes

My app registers for APNS push notifications and didRegisterForRemoteNotificationsWithDeviceToken get called with a deviceToken. I call Google GCM API's tokenWithAuthorizedEntity with the deviceToken to get a token for Google APIs. Can I use that token in the server as deviceRegistrationId when sending a push notification to the device (using GCM)? Or do I need to convert the Apple's deviceToken to a string and use that? The deviceToken is NSData, but GCM API requires a string.

1

1 Answers

0
votes

You need to convert deviceToken to string (NSString) as APNS recognizes its own device tokens only and not from any other services. Use this code:

NSString* newDeviceToken = [[[[deviceToken bytes]
                 stringByReplacingOccurrencesOfString: @"<" withString: @""] 
                stringByReplacingOccurrencesOfString: @">" withString: @""] 
               stringByReplacingOccurrencesOfString: @" " withString: @""];