Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud Push, recommend approach / examples #1106

Closed
camstuart opened this issue Jan 20, 2017 · 10 comments
Closed

Cloud Push, recommend approach / examples #1106

camstuart opened this issue Jan 20, 2017 · 10 comments

Comments

@camstuart
Copy link
Contributor

What's the recommended cloud messaging approach for Tabris.

CloudPush (http://developer.eclipsesource.com/tabris/docs/2.0/working/client-services/cloud-push/)

Seems fairly involved, requiring Xcode to set up an "application delegate"

And firebase cloud messaging support was not clear (platforms, Tabris version)

In the current day, what is the recommended approach? And is there a clear example or tutorial?

@mpost
Copy link
Member

mpost commented Jan 23, 2017

For Android we have developed the plugin https://github.com/eclipsesource/tabris-plugin-firebase. It allows you to use firebase cloud messaging with Tabris.js (2.x). For iOS there are several cordova plugins available that support the Push Message mechanics.

@camstuart
Copy link
Contributor Author

Ok, great to know. so the firebase plugin wouldn't work for iOS? can you suggest the list of compatible cordova plugins please?

@patrykmol
Copy link
Contributor

This plugin works with iOS https://github.com/eclipsesource/phonegap-plugin-push. However it has been modified and only supports APNS. The GCM part has been removed. JS API remained unchanged.

@bFlood
Copy link

bFlood commented Jan 30, 2017

if you use Pushwoosh, I updated their cordova plugin to work with tabris. It seems to work well on iOS and Android although I have not tested some of their advanced features (location tracking etc)

https://github.com/spatialdatalogic/pushwoosh-phonegap-plugin

@camstuart
Copy link
Contributor Author

@bFlood Would you happen to have an example config.xml that shows the plugin being loaded, and how to call it in Javascript? The docs on pushwoosh show onDeviceReady, but as I understand it, we don't need that in Tabris-js. Thanks in advance

@mpost
Copy link
Member

mpost commented Feb 6, 2017

@camstuart That is correct. You don't have to wait for the device ready callback. The plugin is available instantly.

@bFlood
Copy link

bFlood commented Feb 6, 2017

plugin.xml

<plugin name="pushwoosh-cordova-plugin" spec="https://github.com/spatialdatalogic/pushwoosh-phonegap-plugin" />

and like @mpost mentioned above, plugins are available immediately, so you can call this from anywhere

Server.prototype.initPushwoosh = function() {
    try {

        var pushNotification = cordova.require( 'pushwoosh-cordova-plugin.PushNotification' );

        var self = this;

        if (util.isAndroid()) {


            //============
            //Android

            //set push notifications handler
            document.addEventListener('push-notification', function (event) {
                var title = event.notification.title;
                var userData = event.notification.userdata;

                if (typeof(userData) != "undefined") {
                    var module = util.safeGet(userData, "module", "");
                    var type = util.safeGet(userData, "type", "");
                    var iid = util.safeGet(userData, "iid", "");
                    self.processPushNotification(module, type, iid);
                }
            });

            //initialize Pushwoosh with projectid: "GOOGLE_PROJECT_NUMBER", pw_appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
            pushNotification.onDeviceReady(
                {projectid: "1234567890", pw_appid: "12345-67890"}
            );

            //register for pushes
            //fast Google Pixel device caused issue here, can functions get executed out of order? 
            //delay the registerDevice call to fix the issue
            window.setTimeout(function() {
                pushNotification.registerDevice(
                    function (status) {
                        util.log(status);
                        var pushToken = status.pushToken;

                        util.setItem("_pndt", pushToken);
                    },
                    function (status) {
                        util.log(['failed to register ', status]);
                    }
                );
            }, 200);


        } else {

            //============
            //iOS


            //set push notification callback before we initialize the plugin
            document.addEventListener('push-notification', function (event) {
                //get the notification payload
                var notification = event.notification;

                //TODO - figure out what comes through iOS
                util.log(notification);


            });

            //initialize the plugin
            pushNotification.onDeviceReady({pw_appid: "12345-67890"});

            //register for pushes
            pushNotification.registerDevice(
                function (status) {
                    var deviceToken = status['pushToken'];
                    util.log('registerDevice: ' + deviceToken);
                    util.setItem("_pndt", deviceToken);
                },
                function (status) {
                    util.log(['failed to register ', status]);
                }
            );
        }


    } catch (e) {
        util.log("PUSH NOTIFICATIONS failed to initialize");
    }
};

@camstuart
Copy link
Contributor Author

Fantastic @bFlood thanks for your great example, really appreciated. I have it working now.

In my case I removed the outer callback

Server.prototype.initPushwoosh = function() {

because Server was not defined

And the event notification response data on iOS looks like this:

{  
   foreground:true,
   onStart:false,
   ios:{  
      aps:{  
         alert:"This is the push message text",
         sound:"default",
         badge:0
      },
      p:"7"
   },
   message:"This is the push message text"
}

Mostly options selected in the push woosh UI

@bFlood
Copy link

bFlood commented Feb 14, 2017

great, glad it helped. Pushwoosh is extra money but it does make working with all push on all platforms a little easier IMO. cheers

@ralfstx ralfstx added doc and removed doc labels May 17, 2017
@mpost
Copy link
Member

mpost commented Jun 14, 2017

Closing this as resolved. Please reopen if you have any more issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants