APN deviceToken到GCM deviceRegistrationId

时间:2015-07-29 13:56:52

标签: ios apple-push-notifications google-cloud-messaging

我的应用程序注册APNS推送通知,并使用deviceToken调用didRegisterForRemoteNotificationsWithDeviceToken。我使用deviceToken将Google GCM API的tokenWithAuthorizedEntity称为获取Google API的令牌。在向设备发送推送通知时(使用GCM),我可以在服务器中将该令牌用作deviceRegistrationId吗?或者我是否需要将Apple的deviceToken转换为字符串并使用它? deviceToken是NSData,但GCM API需要一个字符串。

1 个答案:

答案 0 :(得分:0)

您需要将deviceToken转换为字符串(NSString),因为APNS仅识别其自己的设备令牌,而不是来自任何其他服务。使用此代码:

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