the*_*atp 10 ios uilocalnotification ios5
我现在已经实现UILocalNotifications
了两个不同的应用程序.一个使用位置服务,这意味着如果它被杀死,它(通常)会重新启动(所以它不是一个大问题).但是,在另一个应用程序中,我UILocalNotification
根据时间安排.在这种情况下,我遇到了一个重大问题.
如果我安排通知,那么应用程序会被杀死,推出内存,电话关闭然后再打开,我无法在打开应用程序时"自动"查看旧通知.
这是有效的工作流程(app在后台运行):
下面是它工作流程无法正常工作(应用程序不再在后台运行):
didReceiveLocalNotification
调用该方法.用户认为该应用程序不起作用.有什么方法可以知道当应用程序没有在后台运行时它们触及了哪个通知(因此没有运行didReceiveLocalNotification method
)?
use*_*037 16
在第二种情况下,用户已退出(或杀死)应用程序,因此当用户触摸通知时,您的应用程序将启动.
这可以在下面提到的appDelegate的方法中处理
didFinishLaunchingWithOptions
在启动应用程序时调用,因此只需检查应用程序是否实际启动,因为用户触摸了通知(代码如下):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (notification)
{
NSLog(@"notification caused app to launch, alert body = %@", notification.alertBody);
// do what ever action you want to do
// you could just copy the code from "didReceiveLocalNotification" and paste it here
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5831 次 |
最近记录: |