Search code examples
iphoneiosnotificationspush-notificationreminders

how to notify user in ios, while app is closed/ inbackground


i want to notify the user when a "time" is reached.

for example:

i have an tableview with many rows. this rows are something like reminders where the user can set the date and time of remind.
So in a row the reminder is set to 24 April 12:15.
At this time the App is closed.

So how can i notify the user that this time is reached?

Is there a way to do that without apple push notification service?

Edit 1:
Thanks for answering, here is an example for local notifications:

//This example adds 20 seconds to current time, use it for testing 
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];



    NSDate *currentDate = [NSDate date];
    NSDate *currentDatePlus = [currentDate dateByAddingTimeInterval:20];

    localNotification.fireDate = currentDatePlus;
    localNotification.alertBody = @"Hallo ayFon User";
    localNotification.soundName = UILocalNotificationDefaultSoundName;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    [localNotification release];

EDIT 2:

//Add this for iOS 5 Notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
 UIRemoteNotificationTypeAlert |
 UIRemoteNotificationTypeSound];

Solution

  • You have to use the Local Notifications of iOS. They are done in this exact purpose.

    You can find documentation here: Local and Push Notification Programming Guide.