Tab Bar Not Showing - ios

I have a specific view opening when opening my app from a notification. The navigation bar shows up and the navigation works correctly. The problem I'm having is getting the tab bar to show up. Here is my didFinishLaunchingWithOptions method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// This prevents the UA Library from registering with UIApplcation by default when
// registerForRemoteNotifications is called. This will allow you to prompt your
// users at a later time. This gives your app the opportunity to explain the benefits
// of push or allows users to turn it on explicitly in a settings screen.
// If you just want everyone to immediately be prompted for push, you can
// leave this line out.
// [UAPush setDefaultPushEnabledValue:NO];
//Create Airship options dictionary and add the required UIApplication launchOptions
NSMutableDictionary *takeOffOptions = [NSMutableDictionary dictionary];
[takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];
// Call takeOff (which creates the UAirship singleton), passing in the launch options so the
// library can properly record when the app is launched from a push notification. This call is
// required.
//
// Populate AirshipConfig.plist with your app's info from https://go.urbanairship.com
[UAirship takeOff:takeOffOptions];
// Set the icon badge to zero on startup (optional)
[[UAPush shared] resetBadge];
// Register for remote notfications with the UA Library. This call is required.
[[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
// Handle any incoming incoming push notifications.
// This will invoke `handleBackgroundNotification` on your UAPushNotificationDelegate.
[[UAPush shared] handleNotification:[launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]
applicationState:application.applicationState];
// self.tabBarController = [[UITabBarController alloc] initWithNibName:#"KFBViewController" bundle:nil];
KFBViewController *rootView = [[KFBViewController alloc] initWithNibName:#"KFBViewController" bundle:nil];
KFBNavControllerViewController *navController = [[KFBNavControllerViewController alloc] initWithRootViewController:rootView];
navController.delegate = rootView;
UIViewController *aboutUs = [[AboutUs alloc] initWithNibName:#"AboutUs" bundle:nil];
KFBNavControllerViewController *navController1 = [[KFBNavControllerViewController alloc] initWithRootViewController:aboutUs];
UIViewController *contactUs = [[ContactUs alloc] initWithNibName:#"ContactUs" bundle:nil];
KFBNavControllerViewController *navController2 = [[KFBNavControllerViewController alloc] initWithRootViewController:contactUs];
UIViewController *kyfb = [[KYFB alloc] initWithNibName:#"KYFB" bundle:nil];
KFBNavControllerViewController *navController3 = [[KFBNavControllerViewController alloc] initWithRootViewController:kyfb];
// UIViewController *rsfm = [[RSFM alloc] initWithNibName:#"RSFM" bundle:nil];
// KFBNavControllerViewController *navController4 = [[KFBNavControllerViewController alloc] initWithRootViewController:rsfm];
// UIViewController *li = [[LegislatorInfo alloc] initWithNibName:#"LegislatorInfo" bundle:nil];
// KFBNavControllerViewController *navController5 = [[KFBNavControllerViewController alloc] initWithRootViewController:li];
// UIViewController *events = [[Events alloc] initWithNibName:#"Events" bundle:nil];
// KFBNavControllerViewController *navController6 = [[KFBNavControllerViewController alloc] initWithRootViewController:events];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//self.viewController = [[KFBViewController alloc] initWithNibName:#"KFBViewController" bundle:nil];
//self.window.rootViewController = self.viewController;
self.tabBarController = [[KFBTabBarViewController alloc] init];
self.tabBarController.viewControllers = #[navController, navController1, navController2, navController3];
// self.tabBarController.customizableViewControllers = nil;
self.window.rootViewController = self.tabBarController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// If application is launched due to notification,present another view controller.
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (notification)
{
ActionAlertsViewController *actionAlerts = [[ActionAlertsViewController alloc] initWithStyle:UITableViewStylePlain];
WebViewController *wvc = [[WebViewController alloc]init];
[actionAlerts setWebViewController:wvc];
KFBNavControllerViewController *navController7 = [[KFBNavControllerViewController alloc] initWithRootViewController:actionAlerts];
[self.window.rootViewController presentViewController:navController7 animated:NO completion:nil];
}
return YES;
}

Related

How to handle Remote push notifications in didreceiveRemoteNotification in AppDelegate

For my Remote push notifications I have handle like this in my AppDelegate
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
dm=[DataManager sharedManager];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
dm.screenHight=[UIScreen mainScreen].bounds.size.height;
dm.screenWidth=[UIScreen mainScreen].bounds.size.width;
NSLog(#"^^^^^^^^^^^^^^ Screen hight ^^^^^^^^^^^^^ %i",dm.screenHight);
// for PAYPAL
[PayPalMobile initializeWithClientIdsForEnvironments:#{PayPalEnvironmentProduction : #"YOUR_CLIENT_ID_FOR_PRODUCTION",PayPalEnvironmentSandbox : #"AQhrXRAyHg6nuJCma6vkl1ZtxmWUynzuf2temitMSJEZf8n74p9iKAt6TgSf"}];
/// FOR PAYPAL
NSLog(#"%#",userInfo);
NSDictionary *dictionary=[userInfo objectForKey:#"jsonContent"];
dm.notificationDictionary=dictionary;
if ( application.applicationState == UIApplicationStateActive )
{
UIViewController *viewController1;
viewController1 = [[SplashViewController alloc] initWithNibName:#"SplashViewController" bundle:nil];
UINavigationController *aNavigationController=[[UINavigationController alloc] initWithRootViewController:viewController1];
self.navigationcontroller = aNavigationController ;
self.navigationcontroller.navigationBar.hidden=YES;
[self.window setRootViewController:self.navigationcontroller];
[self.window makeKeyAndVisible];
}
else
{
UIViewController *viewController1;
viewController1 = [[SplashViewController alloc] initWithNibName:#"SplashViewController" bundle:nil];
UINavigationController *aNavigationController=[[UINavigationController alloc] initWithRootViewController:viewController1];
self.navigationcontroller = aNavigationController ;
self.navigationcontroller.navigationBar.hidden=YES;
//[self.window addSubview:[self.navigationcontroller view]];
//[self.window setRootViewController:viewController1];
[self.window setRootViewController:self.navigationcontroller];
[self.window makeKeyAndVisible];
}
}
This is working fine. But my problem is when the app is in active state its automatically redirect to the relavent page before click the notification. But I want to keep the apps current screen as it is when it is in the forground and when only user clk the notification redirect to the relavant page. How can I do this? Please help me.
Thanks
If your app is in active state, you can show your notification details in a UIAlertView. User will perform the action through the alert. But you cannot expect the notification in this state.
UIApplicationState appState = [application applicationState];
if (appState == UIApplicationStateActive) {
NSString *cancelTitle = #"Close";
NSString *showTitle = #"Show";
NSString *message = [[userInfo valueForKey:#"aps"] valueForKey:#"alert"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#“Your Title”
message:message
delegate:self
cancelButtonTitle:cancelTitle
otherButtonTitles:showTitle, nil];
[alertView show];
return;
}

Get to specific tabView object from App Delegate

Trying to launch a specific tabView object from the app delegate when you receive a notification, however the app crashes on launch.
Here is the code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *viewController;
CustomTabViewController * tabBar = [[CustomTabViewController alloc] init];
NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
NSString *type = [notificationPayload objectForKey:#"type"];
if([type isEqualToString:#"friend"]){
tabBar.selectedViewController = [tabBar.viewControllers objectAtIndex:2];
self.window.rootViewController = tabBar;
[self.window makeKeyAndVisible];
}
if([type isEqualToString:#"message"]){
tabBar.selectedViewController = [tabBar.viewControllers objectAtIndex:0];
self.window.rootViewController = tabBar;
[self.window makeKeyAndVisible];
}
Any ideas?

UITabBarController wont show

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.main_tabs = [[UITabBarController alloc] init];
self.viewController1 = [[ViewController alloc] initWithNibName:nil bundle:NULL];
self.viewController1.title = #"Home";
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:self.viewController1];
self.viewController2 = [[ViewController2 alloc] initWithNibName:nil bundle:NULL];
self.viewController2.title = #"About";
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:self.viewController2];
self.tabs_array = [[NSArray alloc] initWithObjects:nav1,nav2, nil];
self.main_tabs.viewControllers = self.tabs_array;
[self.window addSubview:self.main_tabs.view];
return YES;
}
This is the code from my appDelegate file. I've added a UITabBarController Programmatically but it won't show up at all. There's no errors or warnings that show up and nothing is logged. Any ideas? Thanks in advance...
Change your code to this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UITabBarController *main_tabs = [[UITabBarController alloc] init];
self.viewController1 = [[ViewController alloc] initWithNibName:nil bundle:NULL];
self.viewController1.title = #"Home";
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:self.viewController1];
self.viewController2 = [[ViewController2 alloc] initWithNibName:nil bundle:NULL];
self.viewController2.title = #"About";
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:self.viewController2];
main_tabs.viewControllers = #[ nav1, nav2 ];
self.window.rootViewController = main_tabs;
return YES;
}

Creating a View Controller that only appears on first app open

I am creating a View Controller that only appears the first time the user opens the app. I had it working by just pushing the welcome view controller, but then I couldn't get it to push the normalViewController when the user was done in the welcomeViewController. I then then tried to set the welcomeViewController as the rootViewController. This still shows the welcomeScreen, but all of the buttons on it do not work. If any one knows how to fix this or a better way to create a welcomeViewController, it would be very much appreciated. Here is the code I am using to show the rootViewController
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"TermsAccepted"]){
NSLog(#"Second time opening the app");
}
else{
WelcomeViewController *welcomeViewController = [[WelcomeViewController alloc] init];
[[UIApplication sharedApplication] keyWindow].rootViewController = welcomeViewController;
}
To create the UITabBar -
self.tabBarController = [[UITabBarController alloc] init];
[[UITabBar appearance] setTintColor:[UIColor redColor]];
// FeedViewController
feedViewController=[[FeedViewController alloc] init];
feedViewController.tabBarItem.image=[UIImage imageNamed:#"Describe Home_Icon_NormalArtboard-1"];
feedViewController.title = #"Timeline";
feedViewController.tabBarItem.title = nil;
//TodayViewController
TodayViewController *todayViewController = [[TodayViewController alloc] init];
todayViewController.tabBarItem.image = [UIImage imageNamed:#"Today_Icon"];
todayViewController.title = #"Today";
todayViewController.tabBarItem.title = nil;
//CreateViewController
self.createViewController = [[CreateViewController alloc] init];
self.createViewController.tabBarItem.image = [UIImage imageNamed:#"Create_Icon"];
self.createViewController.title = #"Create";
self.createViewController.tabBarItem.title = nil;
//AlertViewController
AlertsViewController *alertsViewController = [[AlertsViewController alloc] init];
alertsViewController.tabBarItem.image=[UIImage imageNamed:#"Alerts_IconArtboard-1"];
alertsViewController.title=#"Alerts";
alertsViewController.tabBarItem.title = nil;
//ProfileViewController
ProfileViewController *profileViewController = [[ProfileViewController alloc] init];
profileViewController.tabBarItem.image=[UIImage imageNamed:#"Profile_IconArtboard-1"];
profileViewController.title=#"Profile";
profileViewController.tabBarItem.title = nil;
NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:2];
self.tabBarController = [[UITabBarController alloc] init];
UINavigationController *feedNavigationController = [[UINavigationController alloc] initWithRootViewController:feedViewController];
[tabBarViewControllers addObject:feedNavigationController];
feedNavigationController = nil;
UINavigationController *todayNavigationController = [[UINavigationController alloc] initWithRootViewController:todayViewController];
[tabBarViewControllers addObject:todayNavigationController];
todayNavigationController = nil;
UINavigationController *createNavigationController = [[UINavigationController alloc] initWithRootViewController:self.createViewController];
[tabBarViewControllers addObject:createNavigationController];
createNavigationController = nil;
UINavigationController *alertsNavigationController = [[UINavigationController alloc] initWithRootViewController:alertsViewController];
[tabBarViewControllers addObject:alertsNavigationController];
alertsNavigationController = nil;
UINavigationController *profileNavigationController = [[UINavigationController alloc] initWithRootViewController:profileViewController];
[tabBarViewControllers addObject:profileNavigationController];
profileNavigationController = nil;
self.tabBarController.viewControllers = tabBarViewControllers;
tabBarViewControllers = nil;
[self.window addSubview:self.tabBarController.view];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"TermsAccepted"]){
NSLog(#"Second time opening the app");
rootViewController = // Your new main controller
}
else
{
rootViewController = // Terms and conditions view controller
}
self.window.rootViewController = rootViewController;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
self.window.rootViewController = navigationController;
return YES;
}

uitabbar item 2 not being set as selected item

I have this code in my app delegate:
- (void) refreshTabBar{
if(mainTabBarController){
UITabBarItem *tab1 = [[UITabBarItem alloc] initWithTitle:#"Page1" image:[UIImage imageNamed:#"1_icon.png"] tag:3];
UITabBarItem *tab2 = [[UITabBarItem alloc] initWithTitle:#"Page2" image:[UIImage imageNamed:#"2_icon.png"] tag:1];
UITabBarItem *tab3 = [[UITabBarItem alloc] initWithTitle:#"Page3" image:[UIImage imageNamed:#"3_icon.png"] tag:2];
UITabBarItem *tab4 = [[UITabBarItem alloc] initWithTitle:#"Page4" image:[UIImage imageNamed:#"4_icon.png"] tag:4];
UITabBarItem *tab5 = [[UITabBarItem alloc] initWithTitle:#"Page5" image:[UIImage imageNamed:#"5.png"] tag:0];
[[[mainTabBarController viewControllers] objectAtIndex:3] setTabBarItem:tab1];
[[[mainTabBarController viewControllers] objectAtIndex:1] setTabBarItem:tab2];
[[[mainTabBarController viewControllers] objectAtIndex:2] setTabBarItem:tab3];
[[[mainTabBarController viewControllers] objectAtIndex:4] setTabBarItem:tab4];
[[[mainTabBarController viewControllers] objectAtIndex:0] setTabBarItem:tab5];
//reload the ClaimViewController
//[[[[[mainTabBarController viewControllers] objectAtIndex:2] childViewControllers] objectAtIndex:0] reloadView];
NSLog(#"setting selected tabbar controller index to 2");
mainTabBarController.selectedIndex = 2;
[mainTabBarController setSelectedIndex:2];
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
mainTabBarController = [[UITabBarController alloc] init];
UIViewController *viewController = nil;
viewController = [storyboard instantiateViewControllerWithIdentifier:#"SplashScreenViewController"];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
//initialize objects
facebookNetworkController = [[FacebookNetworkController alloc]init];
//UI cutomizations
[self applyTheme];
//TestFlight SDK
[TestFlight takeOff:#"xxxxxxxxxxx-xxxxxxxx-xxxxxxxxx-xxxxxxx"];
// Let the device know we want to receive push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
// ------ GOOGLE ANALYTICS ------- \\
// Optional: automatically send uncaught exceptions to Google Analytics.
[GAI sharedInstance].trackUncaughtExceptions = YES;
// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
[GAI sharedInstance].dispatchInterval = 20;
// Optional: set Logger to VERBOSE for debug information.
[[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelNone];
// Initialize tracker.
tracker = [[GAI sharedInstance] trackerWithName:#"YOYOYOYOYOYO" trackingId:#"UA-43403680-1"];
// NEW RELIC
[NewRelicAgent startWithApplicationToken:#"a6a6a6a6a6a6a6a6a6a6as6as6a6a6"];
[self refreshTabBar];
NSLog(#"Application did finish launching");
return YES;
}
For some reason it does not select this index.
What am I doing wrong?
[[mainTabBarController tabBar] setSelectedItem:[[[mainTabBarController tabBar] items] objectAtIndex:2]];
'Directly modifying a tab bar managed by a tab bar controller is not allowed.'
You can use [mainTabBarController setSelectedIndex:2];
Let this work be done by controller of tab bar.

Resources