Reputation: 21986
I see iOS applications like Facebook that send notifications even if the application hasn't been launched.
I need to schedule a task with a timer that gets executed at every time interval, and this task (should be inside the same application) should deliver a NSUserNotification
if meets some conditions.
How can you set up such a notification even if the application isn't running?
Upvotes: 2
Views: 409
Reputation: 77251
Scheduled notifications can be done with local notifications, using UILocalNotification. However, like push notifications, local notifications cannot run code. They present a notification to the user, who may or may not choose to start your app in response.
If you want to run code in your app on a timed schedule, then your app has to run in the background. And Apple limits background apps to only a few specific purposes. If your app doesn't fall in one of those categories your app can't run in the background (see UIBackgroundModes key).
Significant location change monitoring can start you app when a location change has occurred but that is location based not time based and cannot be scheduled.
Upvotes: 2
Reputation: 5534
Facebook app and other apps that send notifications when they were not launched do this by using the remote notification mechanism.
To use this, you need to setup a server, create push certificates and use a APNS library for your preferred server.
Take a look here for details: http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12
Upvotes: 7
Reputation: 45210
It cannot be done in the way you think, you (like Facebook) should use Apple Push Notification Service.
Upvotes: 1