HI.

I am building an app with Cordova(6.0.0)/PhoneGap(5.3.10)

When i add Pushwoosh plugin (4.2.2), and using an Android device, everything works fine. But for iOS, the app dosent work and suddenly opens Pushwoosh documentation page, and not the app itself? https://rawgit.com/Pushwoosh/pushwoosh-phonegap-3.0-plugin/master/Documentation/files/PushNotification-js.html

I am not sure what i am doing wrong, since it works fine on Android. I followed the instructions from Pushwoosh docs: http://docs.pushwoosh.com/docs/cordova-phonegap

asked 04 Apr '16, 11:17
Martin's gravatar image

Martin
113

edited 04 Apr '16, 11:37

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

permanent link
answered 04 Apr '16, 12:09
PavelB's gravatar image

PavelB
513

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?

permanent link
answered 04 Apr '16, 12:32
Martin's gravatar image

Martin
113

edited 04 Apr '16, 12:33

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×353
×326
×190
×165

question asked: 04 Apr '16, 11:17

question was seen: 1,865 times

last updated: 04 Apr '16, 12:33