App42: push notifications don’t come on ios device

492 views Asked by At

Context:
I’m trying to migrate my cocos2d-x(v.3.8.1) application from Parse to App42. Everything is fine, except the push notifications.
What I do:
I follow this guide:

-make App42 compatible .p12 certificates using .p12->.pem->.p12 transformation
- upload this certificates on App42, they are highlighted in green on the server
- download and install the latest App42 SDK ver.2.1 for Cocos2d-x
- register push notifications in 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 with APNS in my singleton 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);
    }
}

So, registration process is fine. I get "Push notification service registered!" in logs, on the server App42 Cloud API -> Unified Notifications -> Push Users I can see the created user with the correct device token.
I select it on the server and push him notification, this notification is displayed as sent. But I can receive any notification on my device.
I was trying to do:
I tried to use Push Notification Plugin for Cocos2d-x with the same result.
Also I used APN Tester, it logs «Failure performing handshake, error code -9806».
I can try App42 SDK for iOS also, but this would lead to rewrite the whole App42Methods class. I would like to avoid this.
Push notifications worked fine on the Parse.com.

Please tell me what am I doing wrong? Seems App42 doesn’t connect to APNS, but I have no idea why.
Any help will be appreciated.

1

There are 1 answers

1
Rajeev On BEST ANSWER

Handshake issue generally comes due to problem in p12 file. You can refer this post for the same. I will suggest you to recreate your .p12 file following the same tutorial and try. If you still face the issue then you can write at [email protected] or App42 community forum for quick resolution.