ios handle pushnotification in background

只谈情不闲聊 提交于 2019-12-24 11:56:27

问题


I want to save a push notification that arrives when the application is in background state. I know about

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

This delegate method is called when the app is in foreground or background (if the user just clicks on the received notification).

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

This method is called only once when the app starts.

What if the user doesn't click on the notification? How can I save the data of that notification in the database of my app in that case?


回答1:


For this case, you can't save the data in the 'database of [your] app'; instead you save the data in the database on your server, which is where the PushNotification was generated in the first place. Then, when your App is started, it queries your database to get the notification data.




回答2:


If the user doesn't click on the notification, you can't save that data. Even if the user opens the app by tapping its launch icon the app won't receive that data.

Also remember the design of notification is to deliver small payload to alert the user. Once the users starts the app, the app can download the real data you want to save.



来源:https://stackoverflow.com/questions/17067955/ios-handle-pushnotification-in-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!