GithubHelp home page GithubHelp logo

appfeel / cordova-push-notifications Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 25.0 285 KB

Phonegap, Cordova, Intel XDK push notifications support

License: MIT License

JavaScript 51.91% Ruby 0.32% HTML 4.14% CSS 2.84% Java 22.52% Objective-C 14.27% C# 4.01%

cordova-push-notifications's People

Contributors

anulman avatar appfeel avatar miqmago avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cordova-push-notifications's Issues

Cordova 5.4.1 deprecated type generates 12 warnings

Love your plugin. Fewest number of issues I've seen reported. It just works.

BUT: I am seeing the following 12 times and it will only get worse in Cordova 6.2.0 (next version)

Plugins/cordova-push-notifications/PushPlugin.m:137:61: warning: 'enabledRemoteNotificationTypes' is deprecated: first deprecated in iOS 8.0 - Please use -[UIApplication isRegisteredForRemoteNotifications], or -[UIApplication currentUserNotificationSettings] to retrieve user-enabled remote notification and user notification settings [-Wdeprecated-declarations]
NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]

Do not know if this is something you can control or not or what the right type should be.

Problem with device token in ios

I face problem with creating token id in ios build. i used your sample code as it is works for me to create token-id in android but still i didn't get token id on IOS.

I used intel xdk for this. I pass .p12 certificate & other certificates.

This is my total script i put in my index file i try to put as it is code but there us permission problem(While Attaching documents requires write permission to this repository).

This is devicready function -
var pushNotification;

        function onDeviceReady() {
            $("#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);*/

Here i provided dummy Sender Id-

            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":"981362976531","ecb":"onNotification"});        // required!
                } else {
                    pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"});    
                    // required!
                }
            }
            catch(err) 
            { 
                txt="There was an error on this page.\n\n"; 
                txt+="Error description: " + err.message + "\n\n"; 
                alert(txt); 
            } 
        }

Here i want - e.reg to send on server i didn’t get regId even i cannot debug my application i copy paste android - switch case as it is-

        // handle APNS notifications for iOS
        function onNotificationAPN(e) {
            if (e.alert) {
                 $("#app-status-ul").append('<li>push-notification: ' + e.alert + '</li>');
                 // showing an alert also requires the org.apache.cordova.dialogs plugin
                 navigator.notification.alert(e.alert);
            }

            if (e.sound) {
                // playing a sound also requires the org.apache.cordova.media plugin
                var snd = new Media(e.sound);
                snd.play();
            }

            if (e.badge) {
                pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge);
            }

             switch( e.event )
            {
                case 'registered':
                if ( e.regid.length > 0 )
                {
                    $("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
                        passDeviceId(e.regid);
                    // Your GCM push server needs to know the regID before it can push to this device
                    // here is where you might want to send it the regID for later use.
                    console.log("regID = " + e.regid);
                }
                break;                    


                default:
                    /*$("#app-status-ul").append('<li>EVENT -> Unknown, an event was received and we do not know what it is</li>');*/
                break;
            }
        }

Here code for Android which gives me - e.regid
Which i have to pass server. Also worked successfully.

        // handle GCM notifications for Android
        function onNotification(e) {
           /* $("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');*/

            switch( e.event )
            {
                case 'registered':
                if ( e.regid.length > 0 )
                {
                    $("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
                        passDeviceId(e.regid);
                    // Your GCM push server needs to know the regID before it can push to this device
                    // here is where you might want to send it the regID for later use.
                    console.log("regID = " + e.regid);
                }
                break;

                case 'message':
                    // if this flag is set, this notification happened while we were in the foreground.
                    // you might want to play a sound to get the user's attention, throw up a dialog, etc.
                    if (e.foreground)
                    {
                        /*$("#app-status-ul").append('<li>--INLINE NOTIFICATION--' + '</li>');*/

                            // on Android soundname is outside the payload. 
                                // On Amazon FireOS all custom attributes are contained within payload
                                var soundfile = e.soundname || e.payload.sound;
                                // if the notification contains a soundname, play it.
                                // playing a sound also requires the org.apache.cordova.media plugin
                                var my_media = new Media("/android_asset/www/"+ soundfile);
                        my_media.play();
                    }
                    else
                    {   // otherwise we were launched because the user touched a notification in the notification tray.
                        /*if (e.coldstart)
                            $("#app-status-ul").append('<li>--COLDSTART NOTIFICATION--' + '</li>');
                        else
                        $("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>');*/
                    }

                    /*$("#app-status-ul").append('<li>MESSAGE -> MSG: ' + e.payload.message + '</li>');*/
                    //android only
                    /*$("#app-status-ul").append('<li>MESSAGE -> MSGCNT: ' + e.payload.msgcnt + '</li>');*/
                    //amazon-fireos only
                   /* $("#app-status-ul").append('<li>MESSAGE -> TIMESTAMP: ' + e.payload.timeStamp + '</li>');*/
                break;

                case 'error':
                    /*$("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg + '</li>');*/
                break;

                default:
                    /*$("#app-status-ul").append('<li>EVENT -> Unknown, an event was received and we do not know what it is</li>');*/
                break;
            }
        }

        function tokenHandler (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) {
           /* $("#app-status-ul").append('<li>success:'+ result +'</li>');*/
        }

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

        document.addEventListener('deviceready', onDeviceReady, true);

Through this function i can send to

     function passDeviceId(deviceid) {
var http = new XMLHttpRequest();
var url = "http://www.example.com/index.php/api/app/register_device/format/json";
var id = '';
if(window.localStorage.getItem("id") != undefined){
    id = window.localStorage.getItem("id");
}
var params = "deviceid=" + deviceid + "&id="+ id;
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function () { //Call a function when the state changes.
    if (http.readyState == 4 && http.status == 200) {            
        //JSON.parse(http.responseText)[0].dev_id;            
        window.localStorage.setItem("id") = JSON.parse(http.responseText)[0].dev_id;
    }
}
http.send(params);

}
</script>

Do i need to upload something to GCM (FCM) InvalidRegistration iOS

Im getting InvalidRegistration but the registration return me a registrationID like this;
b4b2147d9a6b7ccbfb47f7a821d3ebf9ac89bf418b11d2d887b174bca77XXXXX
Im not sure if its a valid GCM Token or is a APN ID.

Searching on internet found something to upload p12 files to GCM

Event trigger when user clicked on the notification alert.

Hi,

May I know what event will trigger when user click on the notification alert? For example, the app is closed and if user clicked on the notification alert, I want show the page based on the notification alert message. How can I achieve that?

Thanks and appreciate your help.

IOS 11 app in foreground crash

Notifications work perfectly when the app is in the background. When it is in the foreground it crashes the main thread. I am using the WKwebview plugin. Also note that in a desktop browser, I can call the jsCallBack function without any issues. The below snippet is from PushPlugin.m

Any suggestions?

    [jsonStr appendString:@"}"];
    NSString *jsCallBack = [NSString stringWithFormat:@"%@(%@);", self.callback, jsonStr];
   
    NSLog(@"CALLBACK %@", jsCallBack); //added just to see what it had for the callback

    //the line below seems to be the offending line
    [self.webView performSelectorOnMainThread:@selector(evaluateJavaScript:completionHandler:) withObject:jsCallBack waitUntilDone:NO];
      
    self.notificationMessage = nil;
  }
}

iOS Entitlements Not Set

It appears the plugin.xml file is missing the necessary entitlements for iOS to function properly.

<config-file target="*-Info.plist" parent="UIBackgroundModes">
    <array>
        <string>remote-notification</string>
    </array>
</config-file>
<config-file target="*-Debug.plist" parent="aps-environment">
    <string>development</string>
</config-file>
<config-file target="*-Release.plist" parent="aps-environment">
    <string>production</string>
</config-file>

pushNotification.register is not working

I am facing issues in getting APN's device token for Cordova ios.

My Plugins:
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-whitelist 1.3.4 "Whitelist"
cordova-push-notifications 1.2.4 "Push Notifications Plugin"

iOS version - 5.0.1

onDeviceReady: function() {
this.receivedEvent('deviceready');
var pushNotification = window.plugins.pushNotification;
pushNotification.register(
tokenHandler,
errorHandler,
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
},

tokenHandler: function(result) {
alert('device token = ' + result);
},
errorHandler: function(error) {
alert('error');
},

onNotificationAPN: function(data){
alert('notify');
}

I am not getting notification permission alert also. Can anyone help me to resolve this

iOS 13 Device token key is broken

Hi,

As per the apple updates, iOS device token key is generating {length = 32, bytes = 789dc438 6d688f2c ... f6b37ddb 8a504523 }" instead of <789dc438 6d688f2c e2dd66d8 0d335454 5ce29f0f ed71234a f6b37ddb 8a504523>"

For reference, please go through this link.
https://fluffy.es/4-ios13-breaking-changes/#push

So, what is the fix for this, I'm using cordova push notification plugin only and I'm facing this problem.Any updates?

Does not work on iOS 8 Cordova 5.4.1

Love your plugin. Simplest of all the versions I've seen and it JUST WORKS.

Until I had to upgrade to Cordova 5.4.1.

Now I have 2 items:

1 item one is here:

cordova-push-notifications/PushPlugin.m:203:23: error: no visible @interface for 'UIView' declares the selector 'stringByEvaluatingJavaScriptFromString:'
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.