Reputation: 11
How to show a local notification alert or a local notification banner when App is closed (either in the background or foreground), I can only modify the badge number when the app is closed...
Upvotes: 1
Views: 1778
Reputation: 6040
As of the writing of this answer, using iOS 8.4 (soon iOS9), you CAN
UILocalNotifications
when the app is closedpush
notifications whenever you want.If your local notification is scheduled, it WILL fire, wheter or not the app is foreground/background/killed.
So now, your problem is this one : How do I schedule a local notification when the app is forground/background/kill ?
It's easy, in the Appdelegate, you can simply follow any tutorial and type your code there, it's pretty straightforward. The only different thing is, if the app is killed, you can't execute code unless the app is awaken with a push notification. And that's where the remote push notifications are useful, you can awaken your app (and execute code) with a push notification and do whatever you need from here on out.
You could : - Display the content you want with the actual push notification. " You have 1 new message! " - Send a "silent" push notification (invisible by the user) that still awakens your app, and execute code there, for example to update data or modify stuff in your app in general. If I'm not mistaken you're only allowed 15 minutes of work and a certain amount of data transfer when the app is awaken like that, but that has to be verified.
I hope I helped :)
Upvotes: 0
Reputation: 3954
You will not be able to present notifications while the app is in the background unless you implement Push Notifications with APNS and use UIRemoteNotification
. Based on your experience and the scope of the project, it may be a bit complicated, but here is a good reference on getting started:
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
Upvotes: 2