在后台模式didReceiveRemoteNotification不叫

编程入门 行业动态 更新时间:2024-10-25 02:22:21
本文介绍了在后台模式didReceiveRemoteNotification不叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我工作的推送通知,我接收到的数据是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不叫

本文发布于:2023-11-27 10:11:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637645.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不叫   后台   模式   didReceiveRemoteNotification

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!