Search code examples
iphonesdknotificationsalertsreminders

iPhone App - Generate Alert Popups when App is Closed


In creating an iPhone app, is it possible to generate a popup alert on the iphone (similar to a Push notification) when the app has been closed. A simple example would be to have an app that can set a reminder at 5:00PM January 5th, 2010. The app can be closed and the reminder will popup at that time. I don't think this is possible but would like to know if anyone has any ideas? Again, i do not want a Push solution but rather a solution that does not require internet access (i.e. "local" push from iPhone). Thanks.


Solution

  • You can do it now! And it's really rather simple. Create a UILocalNotification.

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
            if (localNotification == nil)
                return;
    //Initialise notification
            localNotification.fireDate = yourDate;
            localNotification.timeZone = [NSTimeZone defaultTimeZone];
            localNotification.alertBody = [NSString stringWithFormat:NSLocalizedString(@"Hey, you've forgotten something", nil)];
            localNotification.alertAction = [NSString stringWithFormat:NSLocalizedString(@"%@", nil), buttonTitle];
            localNotification.soundName = UILocalNotificationDefaultSoundName;
            [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
            [warningDate release];
            [localNotification release];