无法从 didFinishLaunchingWithOptions 函数获取 launchOptions 数据
Can't get launchOptions data from didFinishLaunchingWithOptions function
我的应用需要从 Remotenotification 获取一些数据,以便像 FACEBOOK 应用一样将第一页推送到特定页面,但现在我无法从它始终显示的 didFinishLaunchingWithOptions 函数获取 launchOptions 数据:
Cannot invoke 'objectForKey' with an argument list of type '(String)'.
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
}
我的应用需要从 Remotenotification 获取一些数据,以便像 FACEBOOK 应用一样将第一页推送到特定页面,但现在我无法从它始终显示的 didFinishLaunchingWithOptions 函数获取 launchOptions 数据:
Cannot invoke 'objectForKey' with an argument list of type '(String)'.
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
}