katzer / cordova-plugin-local-notifications

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

iOS 10 Background localnotification ionic-2 #1301

Closed jd0048 closed 6 years ago

jd0048 commented 7 years ago

Expected Behavior

When i am in background local notification is not displaying

Actual Behavior

it must be fired local notification when user application is in background mode also

Steps to Reproduce

put this code in the place when your application gone in background

this.localNotifications.schedule({
                        id: 1,
                        text: 'notification fired',
                        sound: 'file://beep.caf'

                    });
rwillett commented 7 years ago

When do you think your notification will be scheduled?

You have no date for it.

You must put an at: field in. You also need to schedule the date at least a few seconds in the future. You cannot schedule a notification for now.

There are also other issues, you should make your object call to schedule an object inside an array even if there is only one element.

You have no callback success function.

We have no idea if this is correct.

jd0048 commented 7 years ago

we don't need to schedule notification we need instance notification when anything happen in application and its working fine when my application is in foreground so code is perfect just issue with the background mode

jd0048 commented 7 years ago

@rwillett its ionic-2 code

rwillett commented 7 years ago

How are you scheduling notifications in the background? Are you trying to schedule a local notification whilst your app is in the background?

The moment IOS puts an app in the background it is possible that it gets suspended immediately. This means that you cannot schedule anything whilst in the background. Under IOS 8 and 9 it may take up to 15 mins for your app to be suspended, under IOS 10 it may only take seconds as Apple is more aggressive about suspending your app.

This is nothing to do with your app, it is a product of Apple and JavaScript and there is very little you can do about it.

jd0048 commented 7 years ago

@rwillett i had already read all this description in other thread but it will log the console.log data in terminal when anything happen in application just issue is it will not fired in background :(

jd0048 commented 7 years ago

document.addEventListener("pause", () => { console.log("application pause--------->") this.localNotifications.schedule({ id: 1, text: "app in background", sound: "file://beep.caf" }); });

check this code its working fine also in simulator but in actually device it will not fired local notification

rwillett commented 7 years ago

The simulator does NOT work correctly when apps are put in the background. The Xcode simulator keeps apps running and other stuff such as HTTP connections. It does not work the same way as a real device, hence you are managing to execute code in the background.

jd0048 commented 7 years ago

at: new Date(new Date().getTime() + 5*1000)

@rwillett never mind i had try with at and 5 second but its not working

now what should i do?

rwillett commented 7 years ago

So are you running this with the app in the foreground, creating a local notification for five seconds in the future, and then putting the app into the background within five seconds on a real device?

If it works whilst leaving the app in the foreground on a real IOS device, then it looks as if there is a bug in either Ionic 2 or this plugin.

You cannot use Xcode IOS simulator for doing stuff background stuff as its different, things like setTimeout will not suspend in the simulator and will suspend on a real device.

jd0048 commented 7 years ago

yes in foreground its working fine it will fire after 5 second but i have schedule another notification that it will fire when application gone in background but that notification is not fired?

have you got my issue? what problem i am facing in real device?

rwillett commented 7 years ago

Which plugin are you using and how did you install it?

jd0048 commented 7 years ago

cordova plugin add de.appplant.cordova.plugin.local-notification

rwillett commented 7 years ago

Try the ios10 plugin

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

jd0048 commented 7 years ago

Not works

rwillett commented 7 years ago

It works fine for us on Ionic 1.

Suggest you raise this with the Ionic team.

jd0048 commented 7 years ago

if you are not supporting in ionic 2 then why ionic 2 team suggest us to use this plugin for local notifications

rwillett commented 7 years ago

I am not supporting the plugin as I didn't write the plugin, I am helping out people as we use the plugin all the time and it works for us. I have no connection with @katzer other than as a user (and as an administrator here), we are trying to free some time up for him to revise the plugin just to help out.

I cannot speak for why Ionic recommends this plugin. I know it works fine under Ionic 1 as we use it all the time and it works.

jd0048 commented 7 years ago

thank you for your time @rwillett lets wait for @katzer what he/she said about this issue

rwillett commented 7 years ago

You could generate a simple Ionic 1 project, just add your code to this and run it. Shouldn't take more than 20 mins. If it works under there, you know its Ionic 2. If it doesn't work, you know its your code.

jd0048 commented 7 years ago

no sorry i cant do with ionic 1

katzer commented 6 years ago

lets wait for @katzer what he/she said about this issue

he 👍

katzer commented 6 years ago

At the moment I cant tell much things about Ionic. Their current wrapper does not work with 0.9-beta. Because many are using the plugin+ionic I will contribute to the ionic-native wrapper in future.

But for now I am closing all ionic related tickets because they point to old code and/or Ionic.