3
votes

I'm creating a cordova project and use azure mobile app + notification hub service. In the cordova project, I add "cordova-plugin-ms-azure-mobile-apps" and "phonegap-plugin-push" plugins, but when run project I get an error:

Failed to load resource: the server responded with a status of 404 - Cannot GET /push/installations/xxxxx(it's a guid string)

Setup details:

phonegap-plugin-push : version="1.7.2" cordova-plugin-ms-azure-mobile-apps : version="2.0.0-beta5" dev tool : visual studio 2015

Error message pic: enter image description here

var azureClient = new WindowsAzure.MobileServiceClient('http://xxxxxx.azurewebsites.net');

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

        push.on('registration', function (data) {
            azureClient.push.register('gcm', data.registrationId);
        });

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

WindowsAzure.MobileServiceClient is a cordova-plugin-ms-azure-mobile-apps plugin that connect azure mobile apps and azureClient.push.register function will call executeRequest function in MobileServices.Cordova.js (cordova-plugin-ms-azure-mobile-apps plugin)

function executeRequest(client, method, pushChannel, content, installationId, callback) {
    Validate.isString(pushChannel, 'pushChannel');
    Validate.notNullOrEmpty(pushChannel, 'pushChannel');

    var headers = { 'If-Modified-Since': 'Mon, 27 Mar 1972 00:00:00 GMT' };
    headers[constants.apiVersionHeaderName] = constants.apiVersion;

    client._request(
        method,
        'push/installations/' + encodeURIComponent(installationId),
        content,
        null,
        headers,
        callback
    );
}
2

2 Answers

0
votes

This doesn't seem to be directly related to Mobile Apps or Notification Hubs, but rather a Cordova configuration issue.

Either try one of the links below or just search:

Also, there's a step-by-step tutorial on how to Add push notifications to your Apache Cordova app. Might help to verify if what you were doing was similar to what the tutorial suggests.

0
votes

Add the following dependencies in your build.gradle file. And build again.

dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'
    }