2
votes

I'm trying to use Notification Hub to push Cordova app(iOS)

Azure side is as below.

Notification Hub

Notification Hub

Source code on client side is as below. I'm sure Azure client is correctly connected and registration is successful.

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

        var registrationSuccess = function () {
            alert('Registered with Azure!');
        };

        var registrationFailure = function (error) {
            alert('Failed registering with Azure: ' + error);
        };

        push.on('registration', function(data) {
            client.push.apns.registerTemplate(handle,
            'myTemplate', template, null)
            .done(registrationSuccess, registrationFailure);
        });

        push.on('notification', function(data) {
            alert('Push Received: ' + data.message);
        });

        push.on('error', function(e) {
            alert(e.message);
        });

But when I execute Test Send from notification hub page, nothing happens. I tried from simple ruby script to APNS directly and notification comes to iPhone correctly.

Notification Hub Test

Does anyone know how to fix it or any information?

My environment is

  • MacBook Pro
  • OS X ElCapitan
  • Cordova 6.0.0
  • com.microsoft.azure-mobile-services 1.2.9 "Windows Azure Mobile Services"
  • phonegap-plugin-push 1.6.2 "PushPlugin"
1

1 Answers

0
votes

Most likely the call to client.push.register() is not succeeding for some reason. I'm not using the particular plugin you're using, I'm using azure-mobile-apps-cordova-client combined with phonegap-plugin-push. So far, this combination is working for my purposes.

You can find a more complete example here: Add Push Notifications to your Apache Cordova App.

One thing I would add is that when you call the push.register() API in the azure-mobile-apps-cordova-client plugin, you can give it an error function callback that gets called if the API call fails. It would look like this:

push.register('apns', data.registrationId, null, null, function(err) {console.log(err);});

Lastly, in Visual Studio, you can also connect to your notification hub and list and manage the registrations. This is useful to determine if the APNS registration is really accepted.