Open a specific tab/view when user receives a push notification

混江龙づ霸主 提交于 2019-12-18 12:36:12

问题


I want to do something like Twitter app: when someone write me I receive the push notification; if I "slide on the notification" the app starts, but not in the normal stream, it starts in a specific view with the tweet that someone wrote me!

In my app I have something like an RSS reader, and the push notification arrives when there is a new news. So, I want to open the "single news view", and not the main view (that's happening now).

What can I do?

Thanks


回答1:


You can do two things.

One is to check the launchOptions dictionary of the UIApplicationDelegate method

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

to see if the app was launched via a user clicking on a notification. If so, then in that method you can push the appropriate view controller onto the stack, just as you would normally with in-app usage.

If the app is already open, but in the background then the same theory applies but instead use the UIApplicationDelegate method

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

See this link for information on handling incoming notifications.



来源:https://stackoverflow.com/questions/6734338/open-a-specific-tab-view-when-user-receives-a-push-notification

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