检查从Swift中的UILocalNotification启动
发布时间:2020-12-14 05:00:23 所属栏目:百科 来源:网络整理
导读:这是 How to check launchOptions in Swift?的后续问题 – 我的应用程序在没有崩溃的情况下成功启动,但我似乎无法正确检测应用程序何时从通知启动到正常启动. 我正在创建我的UILocalNotification: // set up a frequently recurring notification here just
这是
How to check launchOptions in Swift?的后续问题 – 我的应用程序在没有崩溃的情况下成功启动,但我似乎无法正确检测应用程序何时从通知启动到正常启动.
我正在创建我的UILocalNotification: // set up a frequently recurring notification here just for testing... var fast = UILocalNotification() fast.fireDate = NSDate(timeIntervalSinceNow: 15) fast.alertBody = "Alert Message" fast.timeZone = NSTimeZone.localTimeZone() fast.repeatInterval = NSCalendarUnit.CalendarUnitMinute fast.userInfo = ["Important":"Data"] UIApplication.sharedApplication().scheduleLocalNotification(fast) 这是我从UILocalNotification启动应用程序时尝试处理的代码. func application(application: UIApplication!,didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool { if var launch = launchOptions { if var key = launch.objectForKey(UIApplicationLaunchOptionsLocalNotificationKey) { // I never seem to reach this point... } } return true } 如果我的应用程序是后台运行的,我点击警告框,我想要触发的操作正确执行,所以我知道我至少可以使一条路径正常工作.这里的问题是完全从通知启动应用程序. 解决方法
如果您的应用程序在后台运行,则不会调用“application didFinishLaunching”方法.它已经推出.
在这种情况下,您应该在“application didReceiveLocalNotification”方法中完成工作. func application(application: UIApplication!,didReceiveLocalNotification notification: UILocalNotification!) { // do your jobs here } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |