【发布时间】:2014-07-20 23:53:15
【问题描述】:
这是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
}
如果我的应用程序是后台运行的并且我点击了警告框,我想触发的操作就会正确执行,所以我知道我至少可以让一条路径正常工作。这里的问题是完全从通知中启动应用程序。
【问题讨论】: