简体   繁体   中英

Launch app on specific view controller using iOS8 actionable notifications

I have an actionable notification setup on my app with a YES button. Is it possible, when the notification is triggered and you press the Yes button, to take you into the app on a specific view controller, not the initial view.

Yes you can use new method handleActionWithIdentifier of iOS8 to this task. Whenever you press action button , these delegate will call.

  1. Delegate for localNotification : Called when your app has been activated by the user selecting an action from a local notification.

     - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler 
  2. Delegate for remoteNotification : Called when your app has been activated by the user selecting an action from a remote notification.

     - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler 

Note : You should call the completion handler as soon as you've finished handling the action.

Then you can get your rootViewController using this and then redirect to other ViewController.

- (UIViewController*)GetTopViewController
{
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    UIViewController *rootViewController = appDelegate.window.rootViewController;
    if ([rootViewController isKindOfClass:[UINavigationController class]])
    {
        UINavigationController* rvc = (UINavigationController*)rootViewController;
        rootViewController = rvc.visibleViewController;
    }
    return rootViewController;
}

Other related Question Link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM