When using Cordova/PhoneGap pushwoosh plugin, app opens documentation page?

Comments

2 comments

  • Avatar
    Pavel Boger

    Hello!

    First of all, could you please let me know whether this issue is reproducible on Pushwoosh sample app?

    https://github.com/Pushwoosh/pushwoosh-phonegap-cordova-sample

    Also, if it possible, could you please share your PushNotification.js file, so we could investigate?

    Regards, Paul

  • Avatar
    Msk

    When installing the Pushwoosh sample app and opening the app, is seems to be working, i get a page with a text saying "Hello, Cordova!"

    This is my push function (note: replaced the real app/project ids with xxx):

      function initPushwoosh() {
        if(typeof(cordova) !== 'undefined') {
          // Push for Android
          if(device.platform === 'Android'){
            var pushNotification = cordova.require("pushwoosh-cordova-plugin.PushNotification");
    
            //set push notifications handler
            document.addEventListener('push-notification', function(event) {
                var title = event.notification.title;
                var userData = event.notification.userdata;
    
                if(typeof(userData) != "undefined") {
                    console.warn('user data: ' + JSON.stringify(userData));
                }
    
                alert(title);
            });
    
            //initialize Pushwoosh with projectid: "GOOGLE_PROJECT_NUMBER", pw_appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
            pushNotification.onDeviceReady({  projectid: "xxx", pw_appid : "xxx" });
    
            //register for pushes
            pushNotification.registerDevice(
                function(status) {
                  var deviceType = 3;
                  var deviceId = device.uuid;
                  var hardwareid = device.uuid;
                  var pushToken = status;
                  var token = localStorageService.get('masterToken');;
    
                  var promise = registerDevice(deviceType, deviceId, hardwareid, pushToken, token);
                  promise.then(function(response){
                    console.log('Success!', response);
                  })
                },
                function(status) {
                  console.warn(JSON.stringify(['failed to register ', status]));
                }
            );
          }
          // Push for iOS
          else if(device.platform === 'iOS'){
            var pushNotification = cordova.require("pushwoosh-cordova-plugin.PushNotification");
    
            //set push notification callback before we initialize the plugin
            document.addEventListener('push-notification', function(event) {
              //get the notification payload
              var notification = event.notification;
    
              //display alert to the user for example
              alert(notification.aps.alert);
    
              //clear the app badge
              pushNotification.setApplicationIconBadgeNumber(0);
            });
    
            //initialize the plugin
            pushNotification.onDeviceReady({pw_appid:"xxx"});
    
            //register for pushes
            pushNotification.registerDevice(
              function(status) {
                var deviceToken = status['deviceToken'];
                var deviceType = 1;
                var deviceId = device.uuid;
                var hardwareid = device.uuid;
                var pushToken = status;
                var token = localStorageService.get('masterToken');
    
                var promise = registerDevice(deviceType, deviceId, hardwareid, pushToken, token);
                promise.then(function(response){
                  console.log('Success!', response);
                })
              },
              function(status) {
                console.warn('failed to register : ' + JSON.stringify(status));
                alert(JSON.stringify(['failed to register ', status]));
              }
            );
    
            //reset badges on app start
            pushNotification.setApplicationIconBadgeNumber(0);
          }
        }
      }
    

    What i think is strange, is that it opens the PushNotification documentation and not the app it self, only for iOS and not Android? I can't read somewhere why it does so? If it is due to implementation mistake, certificate mistake or something else?

Please sign in to leave a comment.