我正在使用UILocalNotification对象开发一个警报应用程序。在我的代码中,当警报和用户单击通知面板时,我的应用程序将显示另一个视图控制器。为了满足这种情况,我在下面的不同生命周期中添加了代码:
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self registerNotification];
UILocalNotification *localNotification =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
// Launch VideoVC
application.applicationIconBadgeNumber = 0;
[application presentLocalNotificationNow:localNotification];
}
}
-(void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification{
[self launchMyFunction]
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// How to trigger the notification??????
}
答案 0 :(得分:1)
我终于使用徽章编号来解决它。 感谢所有回答我问题的成员激励我。
- (void)applicationDidBecomeActive:(UIApplication *)application {
if([UIApplication sharedApplication].applicationIconBadgeNumber > 0){
[self myFunction];
}
}
答案 1 :(得分:0)
从didFinishLaunchingWithOptions,你可以像下面这样调用你的didReceiveLocalNotification。
if let notification:UILocalNotification = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as? UILocalNotification {
self.application(application, didReceiveLocalNotification: notification)
}
这段代码很快,您可以在目标c中找到答案。
有一个快乐的编码。