0
votes

I'm trying to send some data through azure mobile service to iOS devices based on what I learned from this tutorial https://github.com/ggailey777/mobile-services-samples/tree/master/CordovaNotificationsArticle ,

However, when I set the payload on azure like this

var payload = '{ "message" : "' + message + '", "title" : "Title...", "id" : "' + recordid + '"  }';

only Android devices can receive additional data on Cordova push plugin notification event, but on iOS, anything other than data.message is undefined.

push.on('notification', function (data) {
    var recordID = data.additionalData.id
});

And here is my code for registration:

    var push = PushNotification.init({
        "android": { "senderID": AzureMobileServiceClient.senderID },
        "ios": { "alert": true, "badge": true, "sound": true }
    });

    push.on('registration', function (data) {

            //// Call mobile service client here 
            var mobileServiceClient = new WindowsAzure.MobileServiceClient(AzureMobileServiceClient.API_URL, AzureMobileServiceClient.API_KEY);

            // Get the native platform of the device. 
            var platform = "";
            if (ionic.Platform.isIOS()) {
                platform = "iOS";
            }
            else {
                platform = "android";
            }

            var tags = [userid, platform];
            // Get the handle returned during registration. 
            var handle = data.registrationId;
            // Set the device-specific message template. 
            if (platform == "android" || platform == "Android") {
                // Template registration. 
                var template = '{ "data" : {"message":"$(message)", "id": "$(id)", "title": "$(title)"}}';
                // Register for notifications. 
                mobileServiceClient.push.gcm.registerTemplate(handle,
                    "myTemplate", template, null, tags)
                    .done(registrationSuccess, registrationFailure);
            } else if (platform == "iOS") {

                // Template registration. 
                var template = '{"aps": {"alert": "$(message)"}}';

                // Register for notifications.             
                mobileServiceClient.push.apns.registerTemplate(handle,
                    "myTemplate", template, null, tags)
                    .done(registrationSuccess, registrationFailure);
            }

        });

Does anyone know how to get additional data on iOS? Any help is much appreciated.

Thanks!

1
Can you show the template you are using in registration? For Apple, custom data is outside the aps node, so a template like {"aps":{"alert":"@{message}", "id":${id}} or so.phillipv

1 Answers

1
votes

The template for the iOS client app registration is as follows:

{"aps": {"alert": "$(message)"}}