2016-04-12 29 views
-1

我正在开发这个iOS应用程序,这不是我第一次处理GCM,但我面临这setAllowGCMRegistrationWithoutAPNSToken错误,我无法在互联网上找到任何东西!set允许没有APNS令牌的GCM注册iOS

这部份的错误消息:

"[[GGLInstanceID sharedInstance] startWithConfig:[GGLInstanceIDConfig defaultConfig]];" 

这部份代码:

- (void)application:(UIApplication)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData)deviceToken { 
// [END receive_apns_token] 
// [START get_gcm_reg_token] 
// Start the GGLInstanceID shared instance with the default config and request a registration 
// token to enable reception of notifications 
[[GGLInstanceID sharedInstance] startWithConfig:[GGLInstanceIDConfig defaultConfig]]; 
_registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken, 
         kGGLInstanceIDAPNSServerTypeSandboxOption:@YES}; 
[[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:_gcmSenderID 
                scope:kGGLInstanceIDScopeGCM 
                options:_registrationOptions 
                handler:_registrationHandler]; 
// [END get_gcm_reg_token]} 
+0

请添加一些代码 – iOS

回答

0

尝试按照本指南setting up a GCM App on IOS

在您可以接收消息之前,iOS应用程序需要注册Apple推送通知服务(APN)和GCM连接服务器。当客户端应用程序注册GCM时,它会收到一个注册令牌,然后它必须发送给应用程序服务器(APNs设备令牌而不是发送到服务器)。客户端应用程序必须存储一个布尔值,该值指示注册令牌是否已发送到服务器。

要使用的APN注册并取得GCM注册令牌:

  1. 附上GCM头:#import <Google/CloudMessaging.h>

  2. 注册远程通知和获得的APN令牌。

  3. 配置和初始化Instance ID,并调用tokenWithAuthorizedEntity:scope:options:handler:使用以下参数:

    • 该应用服务器sender ID

    • kGGLInstanceIDScopeGCM范围,如在GGLInstanceID.h

    • 的APN的标记中定义,设置为选项字典的一部分,使用密钥kGGLInstanceIDRegisterAPNSOption和v alue设置为二进制APNS令牌

    • kGGLInstanceIDAPNSServerTypeSandboxOption对于沙箱值为YES或生产环境为NO。这是选项字典的一部分。

  4. 一旦检索到令牌,将其发送到您的应用服务器。

对于您的错误消息:

[[GGLInstanceID sharedInstance] startWithConfig:[GGLInstanceIDConfig defaultConfig]] 

尝试与

[[GGLInstanceID sharedInstance] startWithConfig:instanceIDConfig] 

入住这fix example of custom delegates更换。