Open a specific tab/view when user receives a push

2019-02-05 05:04发布

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条回答
时光不老,我们不散
2楼-- · 2019-02-05 05:39

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.

查看更多
登录 后发表回答