Cordova pushPlugin not working ios

I'm working with the cordless pushPlugin for a while and all other plugins: https://github.com/phonegap-build/PushPlugin worked great.

but now it doesn't even ask for permission to send notifications. Do you know what happened? Ive tried installing if on 3 apps and the problem is still there, in fact, as if they had updated the version and not there is a bug.

thank

+3


source to share


1 answer


I had problems at first, but now it works fine. Try the code below, it's pretty self explanatory.

And this works on iOS 8 too! I think at first I tried other methods during which I got the iOS 8 app registered and so when I inserted the plugin the registration part was not required again and now I get notifications on iOS 8 too.

Two problems I am facing in iOS 7 is this notification does not clear from the status bar even after I click and open the app and the icons are not showing.



        var pushNotification;
    document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady(){
        console.log("ON DEVICE READY!!!");
        navigator.splashscreen.hide();

        $("#app-status-ul").append('<li>deviceready event received</li>');

        document.addEventListener("backbutton", function(e)
        {
            $("#app-status-ul").append('<li>backbutton event received</li>');

            if( $("#home").length > 0)
            {
                // call this to get a new token each time. don't call it to reuse existing token.
                //pushNotification.unregister(successHandler, errorHandler);
                e.preventDefault();
                navigator.app.exitApp();
            }
            else
            {
                navigator.app.backHistory();
            }
        }, false);

        try
        {
            pushNotification = window.plugins.pushNotification;
            $("#app-status-ul").append('<li>registering ' + device.platform + '</li>');

            if (device.platform == 'android' || device.platform == 'Android' ||  device.platform == 'amazon-fireos')
            {
                pushNotification.register(successHandler, errorHandler, {"senderID":"XXXXXXXXXXXXX","ecb":"onNotification"});       // required!
            }
            else
            {
                pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"false","ecb":"onNotificationAPN"});    // required!
            }
        }
        catch(err)
        {
            txt="There was an error on this page.\n\n";
            txt+="Error description: " + err.message + "\n\n";
            alert(txt);
            console.log(txt);
        }
    }

      

// this part is outside onDeviceReady ()

 function tokenHandler (result)
        {            
            console.log("token:"+result);
//            $("#app-status-ul").append('<li>token: '+ result +'</li>');
            // Your iOS push server needs to know the token before it can push to this device
            // here is where you might want to send it the token for later use.
        }

        function successHandler (result)
        {
            console.log("in succ handler:"+result);
//            $("#app-status-ul").append('<li>success:'+ result +'</li>');
        }

        function errorHandler (error)
        {
            console.log("in errorhandler:"+error);
//            $("#app-status-ul").append('<li>error:'+ error +'</li>');
        } 

      

0


source







All Articles