notification launch custom method/class
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
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 .
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
}
链接地址: http://www.djcxy.com/p/34870.html
上一篇: 使用NSURLProtocol和NSURLSession
下一篇: 通知启动自定义方法/类