我的应用程序需要从 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
}
关于ios - 无法从 didFinishLaunchingWithOptions 函数获取 launchOptions 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30308049/