Hi there,
I'm currently using #ios10 branch and testing local notifications.
I need to test 3 cases:
1) App in foreground
2) App running in background
3) App not running
The both 3 cases works perfectly in any Android that I've tested and in iOS 9.
In IOS10 after a little searching i've got working in foreground using trigger event to do whatever I need to do. Also, if my app is running it works properly. But in case 3 i've got a problem in ios10.
The problem:
My code:
...
cordova.plugins.notification.local.on("click", function (notification) {
//to show my custom popup with opened app.
self.resolveNotification(notification);
}, this);
....
if(ionic.Platform.isIOS() && ionic.Platform.version() >= 10){
cordova.plugins.notification.local.on('trigger', function (notification) {
//to handle notification popup in foreground.
self.resolveNotification(notification);
});
}
...
Is there a proper way to handle it in IOS10 when the app is closed? What should I do?
I'm also seeing this behavior in iOS10. When the app is running in the foreground, the .on('trigger'...) callback will execute, but when the app is running the background, or not running, the function is never executed.
Can confirm that the event is received as expected and that the "click" event will be executed when the app is opened from the background, but "trigger" is not.
Should there be a different listener for the app running the background or not at all?
Can confirm this. LocalNotifications.on("click", ...) is trigged when clicking on notification and app is in foreground. When app is suspended / in background, the method is not called. This happens on Android 7, iOS10 and UWP. We use Ionic 2.0.0.
Is there some trick to getting case 3 working? Doesn't work for me in Android ...
In my apps I try my best not to allow things that are out of my control to dictate what happens when my apps are woken up. This is because whether or not the click or trigger method gets called is out of my control and may work today but can stop working tomorrow鈥攊f and how it works or doesn't is affected by the OS, the packaging of the app and the plugin and the phase of the moon. So I keep track of notifications that "should have fired" and when I wake up I check that list and handle appropriately.
Think about what you really need to happen鈥攊n our case we need to remind our customer to do something so it doesn't matter how the app got launched, we just need to show them the latest reminder. In our case the app behaves the same whether you launch it by clicking a notification or via the home page icon/custom URI etc. Your case may be different but my advice would be that when someone else's software doesn't exactly support what you need, make a note of it and get creative! Consider it insurance against the future.
Actions have been added with 0.9.beta
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.
Most helpful comment
Can confirm this. LocalNotifications.on("click", ...) is trigged when clicking on notification and app is in foreground. When app is suspended / in background, the method is not called. This happens on Android 7, iOS10 and UWP. We use Ionic 2.0.0.