Question

I've searched other questions similar to this here and I can't find any that seem to actually work. What I'm trying to do is when the user opens the app from a local notification, I need it to execute some code (such as opening the UIMessageComposer or displaying a UIAlertView). Anyone have any idea on how I would do this? Just as a note it is a local notification not a push notification.

Was it helpful?

Solution

You need to implement this method in you AppDelegate.m file

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

You can do want you want in this.

Here's a good tutorial on how to work with Local notifications. http://www.appcoda.com/ios-programming-local-notification-tutorial/

OTHER TIPS

use this

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];

if (state == UIApplicationStateActive) {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder"
                                                    message:notification.alertBody
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
}

    // Set icon badge number to zero
    application.applicationIconBadgeNumber = 0;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top