如何在应用未运行或处于锁定屏幕时获取推送通知文本?
我确实尝试过:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
println(userInfo)
// or just
println("something")
}
但它没有打印任何东西。这是错误的功能???
答案 0 :(得分:1)
didReceiveRemoteNotification 函数仅调用此条件。
如果app未在设备 didReceiveRemoteNotification 中运行,则不会调用 在这种情况下,主屏幕中的用户点击通知,我们通过 didFinishLaunchingWithOptions
确定通知是否启动的应用UILocalNotification *localNotif =[launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
您在localNotif.userinfo
尝试使用Swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var userinfo : NSDictionary =launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
print(launchOptions);
return true
}