通过单击应用程序图标直接启动应用程序时未获取推送通知数据 [英] Push notification data not getting when app launched directly by clicking app icon
问题描述
我有一个场景,应用程序将收到推送通知并需要在我的应用程序的主屏幕中显示该消息,为此我将消息数组保存到我的应用程序委托中的用户默认值中,并且一切正常,但在以下条件下它不起作用
I have a scenario in which app will get push notification and need to show that messages in home screen of my app, for that i saved the message array into user defaults from my app delegate and everything works well, but in following conditions it's not working
如果应用程序处于终止状态并且收到通知并且用户通过应用程序图标(不是来自推送通知)触发应用程序
if app is in killed state and a notification came and user triggeres the app through the app icon (not from push notification )
如果应用程序在后台并且收到通知并且用户通过应用程序图标(而不是从推送消息)进入应用程序,在这种情况下也是
if app is in background and notification came and user enters to app through app icon (not from push message ) in this case also
然后我搜索了解决方案并开始了解静默推送通知(用于后台模式),仅此而已,所以我需要知道如何通过推送通知处理所有场景,而我的 appdelegete 是
Then i searched for solutions and came to know about silent push notifications (for background mode) and nothing else so i need to know how to handle all scenarios by push notifications and my appdelegete is
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotif) {
[self handlePushMessage:remoteNotif];
}
return YES;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[self handlePushMessage:userInfo];
}
-(void)handlePushMessage :(NSDictionary*)userInfo{
//method to handle push message
}
提前致谢
推荐答案
这是一个常见问题:如果用户没有通过显示的通知打开您的应用,则无法*获取相关信息.
This is a common issue: if the user does not open your app by means of the displayed notification, there is no* way of getting the related information.
* 许多应用采用的一种可能解决方案是检查远程服务器是否有未读通知(例如,检查未设置的读取日期字段).
* A possible solution employed by many apps is to check with a remote server for unread notifications (e.g. check for an unset read-date field).
这篇关于通过单击应用程序图标直接启动应用程序时未获取推送通知数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!