我是iOS开发的初学者,我正在尝试编写一个支持本地通知的静态库。有没有办法从没有didReceiveLocalNotification,didFinishLaunchingWithOptions的通知中接收事件? 我试过了:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handle:) name:UIApplicationDidFinishLaunchingNotification object:nil];
请帮忙
答案 0 :(得分:0)
我认为不可能(iOS 6.0)包含didReceiveLocalNotification方法的全局观察者。
但是可以为didFinishLaunchingWithOptions方法创建一个全局观察者。
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(notifyApplicationDidFinishLaunching:) name:UIApplicationDidFinishLaunchingNotification object:nil];
-(void)notifyApplicationDidFinishLaunching:(NSNotification*)notification {
NSLog(@"Application did finish launching: %@", notification);
UILocalNotification *localNotification = [notification.userInfo objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
}
使用此观察者可以捕获本地/推送通知,然后应用程序未运行(它已关闭或被杀死)。
如果应用程序在后台,则不会调用此方法。