Note that there are some explanatory texts on larger screens.

plurals
  1. POChange selected tab after receiving Push Notification
    primarykey
    data
    text
    <p>I'm wanting to change the tab that is open when the app is opened from a push notification.</p> <p>At the moment, I have the app registering the notification in the app delegate and running a method in the 1st view controller:</p> <p><strong>AppDelegate.m</strong></p> <pre><code>- (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; } </code></pre> <p><strong>HomeTab_Main.m</strong></p> <pre><code>- (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; } </code></pre> <p>The main issue I'm having is that the alert view is displaying, but the tab isn't changing. When access the app from a notification, I want to automatically switch to the corresponding tab. Does anyone know how this is possible with any examples?</p> <p><strong>Added didFinishLaunchingWithOptions</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload