收到推送通知时打开特定的标签栏 [英] Open specific tab bar when receive push notification
问题描述
在收到推送通知时如何打开特定的标签栏?
How can i open specific tab bar when receive push notification?
我已经放置了 [self.tabBarController setSelectedIndex:2];
放在viewDidAppear上,发生的是数据记录,它显示它通过tabBar 2 viewController传递,但没有打开/显示该页面,而是停留在firstView控制器/第一个tabBar上。
i already put [self.tabBarController setSelectedIndex:2];
on viewDidAppear and what happen is in data logging, it showing that it passing through tabBar 2 viewController but it not open/showing that page and remain at the firstView controller/ first tabBar.
,然后在我终止应用程序并重新打开后,自动/突然打开tabBar 2 viewController。
and then after i terminate the app and open back, automatically/ suddenly it open the tabBar 2 viewController.
任何人都可以提出任何想法或示例代码来解决这个问题?
can anyone give any idea or sample code to solve this?
这是在我的didReceiveRemoteNotification中;
this is in my didReceiveRemoteNotification;
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"Remote notification received");
if([userInfo valueForKey:@"app"]) {
NSString *action_app = [userInfo valueForKey:@"app"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:action_app forKey:@"app"];
NewVC *sample=[[NewVC alloc]init];
[sample viewDidLoad];
//[self.tabBarController setSelectedIndex:2];
[self clearNotifications];
}else{
NSLog(@"---nothing to read---");
}
}
NewVC位于选项卡栏2。
NewVC are located at tabbar 2.
推荐答案
您必须更改tabbar selectedIndex,例如
You have to change tabbar selectedIndex like,
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if([userInfo valueForKey:@"app"]) {
NSString *action_app = [userInfo valueForKey:@"app"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:action_app forKey:@"app"];
UITabBarController *tabb = (UITabBarController *)self.window.rootViewController;
tabb.selectedIndex = 2;
}
}
这篇关于收到推送通知时打开特定的标签栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!