[英]LaunchOptions in didFinishLaunchingWithOptions are nil after Application will be waked up from location
[英]Can't get launchOptions data from didFinishLaunchingWithOptions function
我的应用程序需要从Remotenotification获取一些数据,以便将首页推送到特定的页面(例如FACEBOOK应用程序),但现在我无法从始终显示的didFinishLaunchingWithOptions函数中获取launchOptions数据:
无法使用类型为“(String)”的参数列表调用“ objectForKey”。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let userNotificationTypes = (UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound)
// Register for Push Notitications, if running iOS 8
if application.respondsToSelector("registerUserNotificationSettings:") {
let settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
// Register for Push Notifications before iOS 8
application.registerForRemoteNotificationTypes( UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound | UIRemoteNotificationType.Alert )
}
if let launchOpts = launchOptions {
var notificationPayload: NSDictionary = launchOptions.objectForKey(UIApplicationLaunchOptionsRemoteNotificationKey) as NSDictionary
//Cannot invoke 'objectForKey' with an argument list of type '(String)'.
}
return true
}
请尝试以下方法:
if let notification = launchOpts[UIApplicationLaunchOptionsRemoteNotificationKey] as? [NSObject : AnyObject] {
// extra work
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.