从 AppDelegate 重定向到特定屏幕:点击通知
Redirect to Specific screen from AppDelegate : On tap Notification
对于消息应用程序。
结构是
TabBarController -> NavigationController->View_One -> View_Two. Whenever user tab on notification, i need to redirect to View_2 from appdelegate.m [DidReceiveRemoteNotification method].
当前代码帮助我登陆 View_One。如何在不影响 NavigationController 和 Tabbar 控制器功能的情况下转到 View_Two?
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
if(application.applicationState == UIApplicationStateInactive||application.applicationState == UIApplicationStateBackground){
UIStoryboard *mainSB = [UIStoryboard storyboardWithName:MAIN_STORYBOARD bundle:nil];
UITabBarController *tabBarController = [mainSB instantiateViewControllerWithIdentifier:TAB_BAR_ID];
tabBarController.selectedIndex = 0;
[[UIApplication sharedApplication].keyWindow setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
}
提前致谢。
试试这个
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
if(application.applicationState == UIApplicationStateInactive||application.applicationState == UIApplicationStateBackground){
UIStoryboard *mainSB = [UIStoryboard storyboardWithName:MAIN_STORYBOARD bundle:nil];
UITabBarController *tabBarController = [mainSB instantiateViewControllerWithIdentifier:TAB_BAR_ID];
tabBarController.selectedIndex = 0;
UINavigationController *nav = [tabBarController.viewControllers objectAtIndex:0];
View2 *destViewController = (View2*) [self.nav.viewControllers objectAtIndex:0];
[nav pushViewController:destViewController animated:YES];
}
选择 2
我不确定上述方法是否有效,在这里我们采用一些 hacky 方法,在这里根据您的代码我们使用 NSUSerdefault
概念
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
if(application.applicationState == UIApplicationStateInactive||application.applicationState == UIApplicationStateBackground){
UIStoryboard *mainSB = [UIStoryboard storyboardWithName:MAIN_STORYBOARD bundle:nil];
UITabBarController *tabBarController = [mainSB instantiateViewControllerWithIdentifier:TAB_BAR_ID];
tabBarController.selectedIndex = 0;
[[NSUserDefaults standardUserDefaults]setObject:@"APNS" forKey:@"openVC"]
[[UIApplication sharedApplication].keyWindow setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
}
检索喜欢
- (void)viewDidLoad // or call in loadView Method
{
if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"openVC"]isEqualToString:@"APNS"])
{
// Navigate to second VC
}
}
终于
在你的第二个 VC 上
-(void)viewWillDisappear:(BOOL)animated
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"openVC"];
[super viewWillDisappear:animated];
}
对于消息应用程序。
结构是
TabBarController -> NavigationController->View_One -> View_Two. Whenever user tab on notification, i need to redirect to View_2 from appdelegate.m [DidReceiveRemoteNotification method].
当前代码帮助我登陆 View_One。如何在不影响 NavigationController 和 Tabbar 控制器功能的情况下转到 View_Two?
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
if(application.applicationState == UIApplicationStateInactive||application.applicationState == UIApplicationStateBackground){
UIStoryboard *mainSB = [UIStoryboard storyboardWithName:MAIN_STORYBOARD bundle:nil];
UITabBarController *tabBarController = [mainSB instantiateViewControllerWithIdentifier:TAB_BAR_ID];
tabBarController.selectedIndex = 0;
[[UIApplication sharedApplication].keyWindow setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
}
提前致谢。
试试这个
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
if(application.applicationState == UIApplicationStateInactive||application.applicationState == UIApplicationStateBackground){
UIStoryboard *mainSB = [UIStoryboard storyboardWithName:MAIN_STORYBOARD bundle:nil];
UITabBarController *tabBarController = [mainSB instantiateViewControllerWithIdentifier:TAB_BAR_ID];
tabBarController.selectedIndex = 0;
UINavigationController *nav = [tabBarController.viewControllers objectAtIndex:0];
View2 *destViewController = (View2*) [self.nav.viewControllers objectAtIndex:0];
[nav pushViewController:destViewController animated:YES];
}
选择 2
我不确定上述方法是否有效,在这里我们采用一些 hacky 方法,在这里根据您的代码我们使用 NSUSerdefault
概念
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
if(application.applicationState == UIApplicationStateInactive||application.applicationState == UIApplicationStateBackground){
UIStoryboard *mainSB = [UIStoryboard storyboardWithName:MAIN_STORYBOARD bundle:nil];
UITabBarController *tabBarController = [mainSB instantiateViewControllerWithIdentifier:TAB_BAR_ID];
tabBarController.selectedIndex = 0;
[[NSUserDefaults standardUserDefaults]setObject:@"APNS" forKey:@"openVC"]
[[UIApplication sharedApplication].keyWindow setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
}
检索喜欢
- (void)viewDidLoad // or call in loadView Method
{
if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"openVC"]isEqualToString:@"APNS"])
{
// Navigate to second VC
}
}
终于
在你的第二个 VC 上
-(void)viewWillDisappear:(BOOL)animated
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"openVC"];
[super viewWillDisappear:animated];
}