问题
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