10

I'm trying to get started with Azure Mobile Services and Visual Studio Tools for Apache Cordova. (https://msdn.microsoft.com/en-gb/magazine/dn879353.aspx)

I want to use the Mobile Service for push notifications. I've created the service, with a Node backend, and a TodoItem table. I've got a GCM set up too.

However, when trying to register a template, I get a 404 Not Found error:

 var GCM_SENDER_ID = 'MY_GCM_ID';
 mobileServiceClient = new WindowsAzure.MobileServiceClient(
      "MY_URL",
      "MY_API_KEY"
 );

 pushNotification = PushNotification.init({
    "android": { "senderID": GCM_SENDER_ID }
 });

 pushNotification.on('registration', function (data) {
      var handle = data.registrationId;   //This appears to be set alright
      var platform = device.platform;   // This is 'Android'
      if (platform == 'android' || platform == 'Android') {
        var template = '{ "data" : {"message":"$(message)"}}';
        mobileServiceClient.push.gcm.registerTemplate(handle, 'myTemplate', template, null);
});

The final line gives me a 404. I'm running the app in the Google Android Emulator.

EDIT: I tried calling the registrations endpoint using Postman: https://myservice.azure-mobile.net/push/registrations?platform=gcm&deviceId=

If I do a GET, I get [] as a response, if I do a POST, I get 404

user888734
  • 3,797
  • 5
  • 36
  • 67
  • Can you note what version of the JS file / plugin you have installed? Also what version your Node.js server is? There will be a header when you hit any endpoint (like tables/todoitem) of x-zumo-version : Zumo.master.0.1.6.4401.Runtime. – phillipv Dec 08 '15 at 17:25
  • Thanks. How can I go about looking at the header? I've spent a day or two trying to get the emulator to play nicely with Fiddler, but I can't seem to get anywhere? – user888734 Dec 10 '15 at 14:29
  • You can use Postman app for Chrome, easier than mucking with Fiddler and no need to involve any emulators/etc. – phillipv Dec 10 '15 at 17:47
  • I also realized the 404 could come from NH (and be routed through the mobile service), so you may also want to check your logs tab as well. One easy way to confirm where the 404 comes from is adding a console.log() in your Push script. – phillipv Dec 10 '15 at 17:54
  • I was under the impression that I had to use the emulator rather than Ripple / browser, because push notifications aren't yet supported. Also, please excuse my ignorance - what is NH? – user888734 Dec 10 '15 at 18:06
  • Ah - Notification Hub – user888734 Dec 10 '15 at 18:14
  • To get a PNS token (gcm here) you need a device/emulator. If you have you have a token that's valid, you can do the registration calls from there any way you want (just need to hard code it in). In this case, using postman was just to get a header back and can be on any API you have, not just the push ones. – phillipv Dec 10 '15 at 18:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/97653/discussion-between-user888734-and-phillipv). – user888734 Dec 11 '15 at 14:02

1 Answers1

2

Finally fixed it - I didn't have the Cordova Whitelist Plugin installed!

I realised after debugging into MobileServices.Web.js and seeing that the exact same request that was successful with Postman was failing in the Android Emulator.

user888734
  • 3,797
  • 5
  • 36
  • 67
  • although you have find root cause but still your code has malformed scope, function ` pushNotification.on` is never closed with closing `}` last bracket closes if condition – Pranav Singh Dec 18 '15 at 08:36