2016-02-15 62 views
0

語境:
我試圖從遷移到解析我App42 cocos2d的-X(v.3.8.1)應用程序。一切都很好,除了推送通知。
我做什麼:
我遵循這個guide:使用.p12->.pem->.p12改造
App42:推送通知不來的iOS設備上

-make App42兼容的.p12證書 - 上載App42此證書,他們強調了綠色服務器
上 - 下載並安裝最新的App42 SDK 2.1版的的Cocos2D-X
- 註冊推送通知在Appcontroller.mm

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    … 
     // Register for Push Notitications 
     App42API::Initialize(APP42_KEY, APP42_SECRET); 
     if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { 
      UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge 
                           |UIRemoteNotificationTypeSound 
                           |UIRemoteNotificationTypeAlert) categories:nil]; 
      [application registerUserNotificationSettings:settings]; 
      [application registerForRemoteNotifications]; 
     } else { 
      UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; 
      [application registerForRemoteNotificationTypes:myTypes]; 
     } 
     … 
} 

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    NSString * deviceTokenString = [[[[deviceToken description] 
             stringByReplacingOccurrencesOfString: @"<" withString: @""] 
            stringByReplacingOccurrencesOfString: @">" withString: @""] 
            stringByReplacingOccurrencesOfString: @" " withString: @""]; 
    app42->saveDeviceToken([deviceTokenString UTF8String]); // app42 is my singleton class for App42 methods 
} 

-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings 
{ 
    [application registerForRemoteNotifications]; 
} 

-(void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error 
{ 
    NSLog(@"Failed to get token, error: %@", error); 
} 

-bind App42與APNS在我的單身App42Methods

void App42Methods::saveDeviceToken(string _deviceToken) 
{ 
    int tag = TAG_DEVICE_TOKEN; 
    deviceToken = _deviceToken; 
    string userName = deviceToken.substr(0, 25); 

    PushNotificationService::Initialize(APP42_KEY, APP42_SECRET); 
    DeviceType deviceType = APP42_IOS; 
    PushNotificationService* pushNotificationService = PushNotificationService::getInstance(); 
    pushNotificationService->RegisterDeviceToken(_deviceToken.c_str(), userName.c_str(), deviceType, app42callback(App42Methods::onPushRequestCompleted, this)); 
} 

void App42Methods::onPushRequestCompleted(void *response) 
{ 
    App42PushNotificationResponse *pushResponse = (App42PushNotificationResponse*)response; 
    if (pushResponse->isSuccess) 
    { 
     log("Push notification service registered!"); 
    } 
    else 
    { 
     printf("\nerrordetails:%s",pushResponse->errorDetails.c_str()); 
     printf("\nerrorMessage:%s",pushResponse->errorMessage.c_str()); 
     printf("\nappErrorCode:%d",pushResponse->appErrorCode); 
     printf("\nhttpErrorCode:%d",pushResponse->httpErrorCode); 
    } 
} 

因此,註冊過程是好的。我在日誌中獲得"Push notification service registered!",在服務器上App42 Cloud API -> Unified Notifications -> Push Users我可以使用正確的設備令牌查看創建的用戶。
我在服務器上選擇它並推送通知,此通知顯示爲已發送。但我可以在我的設備上收到任何通知。
我試圖做的事:
我試圖使用Push Notification Plugin Cocos2d-x具有相同的結果。
我還使用APN測試儀,它記錄«Failure performing handshake, error code -9806»
我也可以嘗試iOS的App42 SDK,但這會導致重寫整個App42Methods類。我想避免這一點。
推送通知在Parse.com上正常工作。

請告訴我我做錯了什麼?似乎App42不連接到APNS,但我不知道爲什麼。
任何幫助將不勝感激。

回答

1

握手問題通常歸因於p12文件中的問題。你可以參考this post。我會建議你按照相同的教程重新創建你的.p12文件並嘗試。如果你仍然面臨這個問題,那麼你可以寫在[email protected]App42 community forum快速解決。

+0

非常感謝您的迴應!這是由於缺少蘋果WWDR中級證書。我刪除了舊證書,添加了新的並重新制作.p12文件,現在一切正常! – alc77