0

上下文:
我正在尝试将我的 cocos2d-x(v.3.8.1) 应用程序从 Parse 迁移到 App42。一切都很好,除了推送通知。
我做什么:
我遵循本指南

.p12->.pem->.p12 - 使用转换制作 App42 兼容的 .p12 证书
- 将此证书上传到 App42,它们在服务器上以绿色突出显示
- 下载并安装最新的 App42 SDK ver.2.1 for 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);
}

- 在我的单例中将 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我可以看到创建的用户具有正确的设备令牌。
我在服务器上选择它并向他推送通知,此通知显示为已发送。但我可以在我的设备上收到任何通知。
我正在尝试做:
我尝试使用Cocos2d-x 的推送通知插件,结果相同。
我还使用了 APN 测试器,它记录了«Failure performing handshake, error code -9806».
我也可以尝试适用于 iOS 的 App42 SDK,但这会导致重写整个 App42Methods 类。我想避免这种情况。
推送通知在 Parse.com 上运行良好。

请告诉我我做错了什么?似乎 App42 没有连接到 APNS,但我不知道为什么。
任何帮助将不胜感激。

4

1 回答 1

1

握手问题通常是由于 p12 文件中的问题引起的。你可以参考这篇文章。我建议您按照相同的教程重新创建 .p12 文件并尝试。如果您仍然遇到问题,那么您可以写信至 support@shephertz.com 或App42 社区论坛以快速解决。

于 2016-02-16T06:18:08.820 回答