3

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
    );
}
Nikita R.
  • 7,245
  • 3
  • 51
  • 62
Ian
  • 129
  • 1
  • 8

2 Answers2

0

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.

Community
  • 1
  • 1
Nikita R.
  • 7,245
  • 3
  • 51
  • 62
  • Thanks , but my case only on Mobile Apps and Notification Hubs , and i checked the cordova whitelist configuration , is currect. – Ian Jul 07 '16 at 09:07
  • Could you explain what exactly do you mean by "when run project"? At what point do you get the error message? Build or runtime? If the latter, then could you paste the chunk of code that fails? – Nikita R. Jul 07 '16 at 15:53
  • Hi, Get the error in runtime (debug mode) , publish project to device and use emulator. – Ian Jul 11 '16 at 02:20
  • Could you go through [debugging guidelines](https://msdn.microsoft.com/en-us/library/azure/dn530751.aspx) and also through [diagnostics guidelines](https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-push-notification-fixer/) to see whether you can find a solution? It's still pretty hard to tell without knowing more details about your setup. – Nikita R. Jul 11 '16 at 16:17
  • Stumbled on the same issue. Any solution yet? – Serg Tomcat Sep 29 '16 at 09:47
0

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'
    }