简体   繁体   English

用户在后台收到推送后手动打开应用程序时获取推送通知有效负载

[英]Getting push notification payload when user opens app manually after push has been received in the background

I am using iOS7 and I am trying to determine if I can get the JSON payload in the following situation. 我正在使用iOS7,并且试图确定在以下情况下是否可以获取JSON有效负载。

  • I have background mode "remote-notifications" enabled 我启用了后台模式“远程通知”
  • The push notification is received while the app is terminated 应用终止时收到推送通知
  • The app is launched manually from the icon not from the notification center 该应用是通过图标而不是通知中心手动启动的

When I launch the app from the icon itself after the notification has been received I do not get the push in the launch options from 收到通知后,我从图标本身启动应用程序时,我没有从

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

and the following method does not get called either when app is manually launched from the icon 从图标手动启动应用程序时,以下方法也不会被调用

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

I finally figured out how you can get this! 我终于想出了如何得到这个!

As of iOS 7 you can get it! 从iOS 7开始,您可以获得它!

Basically, you need to configure your application for background remote notifications. 基本上,您需要为后台远程通知配置应用程序。

So, in your info.plist file: For required backgrounds - set it to app downloads content from push notifications. 因此,在您的info.plist文件中: For required backgrounds -将其设置为app downloads content from push notifications.

In the AppDelegate.m file, you need to implement this method: AppDelegate.m文件中,您需要实现此方法:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

See this for how to implement that: didReceiveRemoteNotification: fetchCompletionHandler: open from icon vs push notification 请参阅此内容以了解如何实现该功能:didReceiveRemoteNotification:fetchCompletionHandler:从图标打开与推送通知

For your push notifications, you must have 'content-available': 1, as part of the push notification. 对于您的推送通知,您必须具有'content-available': 1,作为推送通知的一部分。 This is what tells the application that there is new content before displaying the alert. 这就是在显示警报之前告诉应用程序新内容的原因。

See this page for more information on background remote notifications: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/backgrounding/part_3_ios_backgrounding_techniques/updating_an_application_in_the_background/ 请参阅此页面以获取有关后台远程通知的更多信息: http : //developer.xamarin.com/guides/cross-platform/application_fundamentals/backgrounding/part_3_ios_backgrounding_techniques/updating_an_application_in_the_background/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用户通过触摸收到的推送通知来打开应用程序 - User opens application by touching received push notification 收到推送通知后,是否可以修改它? - Is it possible to modify a push notification after it has been received? 如果用户点击通知时应用已经在后台运行,如何获取推送通知的有效载荷? - How can you get the payload of a push notification if app is already running in the background when the user taps the notification? 当应用程序在后台时如何将推送通知有效负载插入数据库 - how to insert push notification payload into database when app is in background 当应用程序在后台运行时,当用户手动启用推送通知时获取 deviceToken - Get deviceToken when user enable push notification manually when app is running in background 当应用程序在iOS 10中处于后台时,未收到推送通知 - Push notification not received when App is in Background in iOS 10 终止后,通过推送通知启动应用程序 - Launch an app with push notification after it has been terminated 如果应用已收到推送通知,请执 - Action if app has received push notification 收到推送通知时在后台执行代码 - Execute code in background when push notification is received 当应用程序在后台时推送通知 - Push notification when app in background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM