1
votes

just want to make sure i'm on the right path.

I'm creating a local notification as an alarm clock. when the user hits button... I want it to DO STUFF.

I'm thinking I have to call my method in

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions .. .for when the application is closed

  • (void)applicationWillEnterForeground:(UIApplication *)application ... for when the application is in the background... when user hits okay

Is there a better way to do what I'm trying to accomplish... DO STUFF when user hits okay on notification?

thanks in advance

2

2 Answers

1
votes

According to the documentation of local and push notifications, you should call application:didFinishLaunchingWithOptions: in both cases :

Handling Local and Remote Notifications

Let’s review the possible scenarios when the operating delivers a local notification or a remote notification for an application.

The notification is delivered when the application isn’t running in the foreground. In this case, the system presents the notification, displaying an alert, badging an icon, perhaps playing a sound. As a result of the presented notification, the user taps the action button of the alert or taps (or clicks) the application icon.

If the action button is tapped (on a device running iOS), the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications). If the application icon is tapped on a device running iOS, the application calls the same method, but furnishes no information about the notification .

1
votes

They can not be forced to call. only Monitoring.

UIApplicationDelegate Protocol

These methods provide you with information about key events in an application’s execution such as when it finished launching, when it is about to be terminated, when memory is low, and when important changes occur. Implementing these methods gives you a chance to respond to these system events and respond appropriately.

If you want you're ViewController get Notification there method. try this

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidFinishLaunching:) UIApplicationDidFinishLaunchingNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];

- (void)applicationDidFinishLaunching:(NSNotification *)noti
{
    //do stuff
}

- (void)applicationEnterForeground:(NSNotification *)noti
{
    //do sutff
}