在后台模式didReceiveRemoteNotification不叫 [英] didReceiveRemoteNotification not called in Background Mode
问题描述
我工作的推送通知,我接收到的数据是JSON格式。我怎样才能解析JSON数据,这在下面的通知中心显示:
I am working on push notifications and the data I receive is in JSON format. How can I parse the JSON data, which is shown in the Notification Center below:
推荐答案
如果你的后台程序/前台模式调用此方法
if your app in background/foreground mode call this method
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
如果你使用上面的方法,你将面临控制台下面的错误
if you used the above method you will face the following error in console
应用:didReceiveRemoteNotification:fetchCompletionHandler:],但你仍然需要远程通知添加到您的支持UIBackgroundModes名单在你的Info.plist
application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
的要解决此问题
请按照步骤的图片
如果您在前台模式的应用程序调用此方法
if your app in foreground mode call this method
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
选择NO-2
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIApplicationState state = [application applicationState];
// user tapped notification while app was in background
if (state == UIApplicationStateInactive || state == UIApplicationStateBackground) {
// go to screen relevant to Notification content
} else {
// App is in UIApplicationStateActive (running in foreground)
// perhaps show an UIAlertView
}
}
斯威夫特
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
var state: UIApplicationState = application.applicationState()
// user tapped notification while app was in background
if state == .Inactive || state == .Background {
// go to screen relevant to Notification content
}
else {
// App is in UIApplicationStateActive (running in foreground)
// perhaps show an UIAlertView
}
}
这篇关于在后台模式didReceiveRemoteNotification不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!