katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.75k forks source link

Local Notification is shown in simulator but not on the device. #1272

Closed sonitgregorio closed 7 years ago

sonitgregorio commented 7 years ago

Hi @katzer im having a problem on local notification for IOS. my problem is it is showing in the simulator but when i tried to run it in the device it does not show the notification and the notification run only when it the application run in background

Regards, Greg

rwillett commented 7 years ago

Fill out the template in #1188 as not enough information.

sonitgregorio commented 7 years ago

@rwillett

Plugin version: 0.8.4 Platform: IOS OS version: 10.3 Device manufacturer / model: Iphone 7 Cordova version (cordova -v): 6.3.1 Cordova platform version (cordova platform ls): IOS Plugin config Expected Behavior Notification will show in the device

Tell us what should happen It will show in the notification center.

Actual Behavior Notification is only showing in the simulator but not on the device

Tell us what happens instead

Steps to Reproduce

I have this code below

LocalNotifications.registerPermission().then(function (register) {
       LocalNotifications.hasPermission().then(function (permission) {
                LocalNotifications.schedule({
                id: self.sugar.Notifcount,
                text: ‘Rental Object : ’ + rental[1] + ' is now ' + value.rental_object_status,
                every: ‘day’,
                data: value.abtz_rental_objects_id_c

           });
    });
});

Reproduce this issue; include code to reproduce, if relevant There is no error.

Context

What were you trying to do? Im trying to show the notification in the notification center and it will show also the notification if the app is open

Debug logs no logs.

Include iOS / Android logs no logs

ios XCode logs Android: $ adb logcat

rwillett commented 7 years ago
  1. You are using the old version of the plugin that doesn't work well on IOS10. Use the 8.5.dev branch

  2. Change your schedule so the object is an array of objects even if you only have one object.

  3. Update template so you have the correct markdown, its wrongly formatted which makes it difficult to read.

  4. No idea what the LED will do as don't think IOS supports it.

It does work in IOS 10 as we use it.

sonitgregorio commented 7 years ago

@rwillett

How do i update my plugin ?

rwillett commented 7 years ago

cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications#ios10

sonitgregorio commented 7 years ago

@rwillett I updated my plugin but still no luck to solve the issue

can i ask for a sample code for the local notification schedule ?

here is my code for notification



 LocalNotifications.registerPermission().then(function (register) {
             console.log(register) //result here is true
             LocalNotifications.hasPermission().then(function (permission) {
             console.log(permission) //result here is true
                    LocalNotifications.schedule({
                         id: self.sugar.Notifcount,
                         text: ‘Rental Object : ’ + rental[1] + ' is now ' + value.rental_object_status,
                         every: ‘day’,
                          data: value.abtz_rental_objects_id_c

                      });

              });
    }); ```
rwillett commented 7 years ago

You have no at: object. You need to create a date to start it off.

every: may also be flaky on IOS10

    function SendDummyNotification() {
        var debugSendDummyNotification = debugFalse;
        var whatAmI = WhatAmI("SetupCongestionNotificationReminders");
    var d          = new Date();
        var now        = d.getTime();
        var year       = d.getFullYear();
    var month      = d.getMonth();
    var day        = d.getDate();
    var reminder0  = new Date(now + 10 * 1000);

        var notifications = [ { id: GetNotificationIdAndIncrement() ,
                                sound: "" , // Turn the sound off
                at: reminder0 ,
                                data: { type: "CongestionChargeNotification" , original_schedule_time: reminder0.getTime()/1000 ,
                                        reminder_type: "reminder0_congestion_charge" , order: 1} ,
                                text: "[A102] Blackwall Tunnel Southern Approach (N/B) - The carriageway is blocked northbound. Collision between two\
 cars. Carriageway blocked. Police on scene are removing vehicles. Expect long delays."
                              }];

        if (whatAmI === "android_app" || whatAmI === "android_simulator")
        {
            for (var i = 0 ; i < notifications.length ; i++)
            {
                notifications[i]["icon"] = "file://pw_notification.png";
            }
    }

        if (debugSendDummyNotification)
            ConsoleLog("SendDummyNotification: " + JSON.stringify(notifications));

    cordova.plugins.notification.local.schedule(notifications , function () {
            if (debugSendDummyNotification)
        ConsoleLog("SendDummyNotification: schedule callback OK");
    });

    }

Read the docs and the issues.

sonitgregorio commented 7 years ago

@rwillett Thank you sir. it fix my issue for this but the notification is not showing when the app is running background. Notification only show when the app is open.

Regards, Greg

rwillett commented 7 years ago

There's something else wrong with your code then. It does work in the background with the app paused or even stopped.

sonitgregorio commented 7 years ago

@rwillett okay i will check this. But why is that my code is running well in simulator ? any idea sir ?

rwillett commented 7 years ago

No idea. You have not provided enough information.

sonitgregorio commented 7 years ago

@rwillett thank you sir for your help. I will try to fix the issue. thanks a lot.

inferno1005 commented 7 years ago

@rwillett I am experiencing the same issue with notifications not firing until the app is opened. I am using the ios10 branch with a simulator.

I am creating the notification like so

window.cordova.plugins.notification.local.schedule({
   text:"test"
})

I walked through the javascript code in safari and it gets all the way to

this.exec('schedule',notifications,callback,scope)

(line number here)

At this point the app is running in the background and there no native code is called. My javascript code is being called from a geofence if you were wondering how it was being run in the background.

Once I manually open the app schedule suddenly runs and creates the notification as expected.

Any advice would be greatly appreciated!

rwillett commented 7 years ago

@inferno1005

Raise a new issue using #1188 . You've not provided enough information and you have a different problem. Do not hijack other peoples threads.

Rob

rwillett commented 7 years ago

@sonitgregorio

What version of the plugin are you really using? You have promises which are not standard in this plugin. Only just noticed the calling routine. Is this the Ionic version of the plugin?

sonitgregorio commented 7 years ago

@rwillett it is now solve sir. thank you for your help :+1:

rwillett commented 7 years ago

So what was the solution?

Please update so other people can learn what the problem is.

sonitgregorio commented 7 years ago

@rwillett i will post my solution after my duty in the office. :) :+1:

sonitgregorio commented 7 years ago

setInterval(function () {
            console.log(self.sugar.Notifcount);
            self.sugar.checkNotif().subscribe(response => {
                _.forEach(response.data, function (value, key) {
                    if (self.sugar.Notifcount > Number(key)) {
                        self.sugar.Notifcount = self.sugar.Notifcount + 1;
                    } else {
                        self.sugar.Notifcount = Number(key) + 1;
                    }
                    var str = value.name;
                    rental = str.split(":")
                    var data = {
                        notification_status: 1
                    }
                    self.sugar.updateRecord('abtz_Notification', value.id, data).subscribe(data => {
                        LocalNotifications.schedule({
                            id: self.sugar.Notifcount,
                            text: 'Rental Object : ' + rental[1] + ' is now ' + value.rental_object_status,
                            sound: null,
                            data: value.abtz_rental_objects_id_c
                        })
                    })
                })
            }, err => {
                console.log(err)
            });
        }, 10000)
``

This how i use the local notification
rozumny commented 7 years ago

why is branch ios10 not included in the master?

ionic plugin add https://github.com/katzer/cordova-plugin-local-notifications#ios10

is it compatible with other ios versions?

divyangpatel0778 commented 6 years ago

Hi @katzer i m having a problem on local notification for Android my problem is it is showing in the simulator but when i tried to run it in the device it does not show the notification and the notification run only when it the application run in background when application kill after that notification is stopped in device but this functionality work in emulator

divyangpatel0778 commented 6 years ago

(window).cordova.plugins.notification.local.schedule({ title: 'Notification Example', message: 'My ultimate is charging..', trigger: { every: 'minute', count:0 }, skipPermission: true });

divyangpatel0778 commented 6 years ago

capture

rwillett commented 6 years ago

@divyangpatel0778

Please raise a new issue. Its not clear what your system is, what you have done, what code you have.