Azure / azure-mobile-services-cordova

Apache License 2.0
23 stars 25 forks source link

Can't register template #19

Closed b3na closed 8 years ago

b3na commented 8 years ago

Hi, I am trying to implement Azure Push Notifications on my Ionic project. I am already accessing a table and the INSERT method is working well, I can access and write on my Azure database.

The problem is when I try to register to get Push notifications, I have a registration ID from gcm and my template, but when I call:

    mobileClient.push.gcm.registerTemplate()

It says Cannot read property gcm of undefined, so my mobileClient instance doesn't have the push method, has something changed? Because I used that same method on a previous Cordova app and it was working well.

Here is the full code for my Push Notifications registration:

    var MOBILE_SERVICE_URL = 'https://XXXX.azure-mobile.net/';
    var MOBILE_SERVICE_APP_KEY = 'XXXXXXXXXXXXXXXXXXX';
    var mobileClient = new WindowsAzure.MobileServiceClient(MOBILE_SERVICE_URL, MOBILE_SERVICE_APP_KEY); 

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

          push.on('registration', function(data) {
              console.log("registration event");
              console.log(JSON.stringify(data));
              console.log($.connection.hub.id);
              var template = "{\"data\":{\"message\":\"$(message)\",\"touserid\":\"$(touserid)\",\"userid\":\"$(userid)\",\"username\":\"$(username)\",\"device\":\"$(device)\"}}"; 
//Registering template with registration id
              mobileClient.push.gcm.registerTemplate(e.regid, "myTemplateBBAndroid", template, [$.connection.hub.id]).done(function () {
              console.log("Registered with hub!");
              }); 
          });
phvannor commented 8 years ago

Nothing should have changed here, what version of the plugin are you using? How about the working project?

b3na commented 8 years ago

I was using 1.2.5 on my previous project, I have no longer access to it. And in this one I am using 1.2.8.

Same error on both iOS and Android, 'push' property of the mobileClient is undefined, but i can use

var mobileClient = new WindowsAzure.MobileServiceClient(MOBILE_SERVICE_URL, MOBILE_SERVICE_APP_KEY); 
mobileClient.getTable( ); 

without problems, so the connection with Azure Mobile Services is working fine.

b3na commented 8 years ago

For some reason my app is not working with the plugin, I added the Mobile Services js manually and now it is working well. Thanks