プッシュ通知からアプリを開いたときに開いているタブを変更したいです。
現時点では、アプリ デリゲートに通知を登録し、最初のビュー コントローラーでメソッドを実行するアプリがあります。
AppDelegate.m
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"didReceiveRemoteNotification");self.apstype = [[NSMutableString alloc] init];self.apstype = [NSMutableString stringWithFormat:@"%@", [[userInfo objectForKey:@"aps"] objectForKey:@"apstype"]];
// Add the tab bar controller's current view as a subview of the window
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
HomeTab_Main *controller = [HomeTab_Main alloc];
[controller receivedNotification];
if (application.applicationState == UIApplicationStateActive){
NSLog(@"UIApplicationStateActive");
} else if (application.applicationState == UIApplicationStateBackground){
NSLog(@"UIApplicationStateBackground");
} else if (application.applicationState == UIApplicationStateInactive){
NSLog(@"UIApplicationStateInactive");
} else {
NSLog(@"else");
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationBar *navigationBarProxy = [UINavigationBar appearance];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
UIImage *backgroundImage = [UIImage imageNamed:@"ge_navigationBar.png"];
[navigationBarProxy setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
UIImage *backgroundImage = [UIImage imageNamed:@"ge_navigationBar~ipad.png"];
[navigationBarProxy setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
}
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
UIColor *tintColour = [UIColor colorWithRed:0.000 green:0.600 blue:0.765 alpha:1];
[[UIBarButtonItem appearance] setTintColor:tintColour];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"Arial-Bold" size:0.0], UITextAttributeFont, nil]];
return YES;
}
HomeTab_Main.m
- (void)receivedNotification
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"%@", appDelegate.apstype);
if([appDelegate.apstype isEqualToString:@"inbox"]){
NSLog(@"goToTab");
[self performSelector:@selector(goToTab) withObject:nil afterDelay:0.1];
}
}
- (void)goToTab
{
NSLog(@"Go to tab");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"1 new message" message:@"click to read" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil, nil];
[alert show];
self.tabBarController.selectedIndex = 2;
}
私が抱えている主な問題は、アラート ビューが表示されているが、タブが変更されていないことです。通知からアプリにアクセスした際に、対応するタブに自動で切り替えたい。例でこれがどのように可能か知っている人はいますか?
didFinishLaunchingWithOptions を追加しました