Im modifying an older ios app which has the mainscreen setup through :
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [UITabBarController new];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self setup];
How can i programatically redirect back to that screen? Im adding a login screen and need to know how to redirect after successful login.
Thanks
#define kUserAuthChangedNotification #"kUserAuthStatusChanged"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self changeRootControllerWithIsUserSignIn:NO];//You must send user sign in or not
[self.window makeKeyAndVisible];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(userAuthStatusChanged) name:kUserAuthChangedNotification object:nil];
}
#pragma mark helper methods
- (void)userAuthStatusChanged {
[self changeRootControllerWithIsUserSignIn:YES];//You must send user sign in or not
}
- (void)changeRootControllerWithIsUserSignIn:(BOOL)isSignIn {
if(isSignIn){
rootViewController = [UITabBarController new];
self.window.rootViewController = rootViewController;
[self setup];
} else {
YourLoginViewController * ctrl = [YourLoginViewController new];
self.window.rootViewController = ctrl;
}
}
When successful login Or log out you must call:
[[NSNotificationCenter defaultCenter] postNotificationName:kUserAuthChangedNotification object:nil];
Related
Basically as the title says, I am having some issues in my WebViewAppDelegate
https://github.com/austin4195/Nucleus-iOS/blob/master/Classes/WebViewAppDelegate.m
Lines 5-48, but I believe the issue is something with defining the item that will store the value
Thanks!
There are a lot of issues with your code:
You have return statement in line 36, so your code is never called.
screenshotTaken should be declared outside of application:didFinishLaunchingWithOptions:.
You should use self.webViewController.theWebView instead webViewController.webView.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
navigationController = [[UINavigationController alloc] init];
navigationController.navigationBar.hidden = YES;
navigationController.toolbar.barStyle = UIBarStyleBlack;
WebViewController *webViewController = [[WebViewController alloc] init];
webViewController.urlString = #"http://files.austinapps.org/File%20Site";
[navigationController pushViewController:webViewController animated:NO];
[webViewController release];
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
self.webViewController = webViewController;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(screenshotTaken)
name:UIApplicationUserDidTakeScreenshotNotification
object:application];
return YES;
}
- (void)screenshotTaken{
[self.webViewController.theWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://website.com/"]]];
}
I my app once user successfully logged In. I will call HOME notification, after that in HomeViewController ViewDidLoad called two times. Can anyone help on this?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//-- Notification Observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(HomeNotification:)name:#"HOME"object:nil];
return YES;
}
#pragma mark - Sidemenu & Home
- (void)HomeNotification:(NSNotification *) notification
{
UIStoryboard *sideMenuSB = [UIStoryboard storyboardWithName:SB_SideMenu bundle:[NSBundle mainBundle]];
SideMenuViewCntrl *sideMenuVC = [sideMenuSB instantiateViewControllerWithIdentifier:VC_SideMenu];
UIStoryboard *HomeSB = [UIStoryboard storyboardWithName:SB_Home bundle:[NSBundle mainBundle]];
HomeViewController *homeVC = [HomeSB instantiateViewControllerWithIdentifier:VC_Home];
UINavigationController *navigationController = [HomeSB instantiateViewControllerWithIdentifier:#"navigationController"];
MFSideMenuContainerViewController *container = nil;
if ([[notification name] isEqualToString:#"HOME"])
{
container = [MFSideMenuContainerViewController containerWithCenterViewController:homeVC leftMenuViewController:sideMenuVC rightMenuViewController:nil];
}
Adding view to window will call viewdidload multiple times?
[container setLeftMenuViewController:sideMenuVC];
[container setCenterViewController:navigationController];
self.window.backgroundColor = [UIColor blackColor];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
}
I have added Home and side menu view controller two times in SideMenu container.
container = [MFSideMenuContainerViewController containerWithCenterViewController:homeVC leftMenuViewController:sideMenuVC rightMenuViewController:nil];
Once I deleted the below code,it works fine now....
[container setLeftMenuViewController:sideMenuVC];
[container setCenterViewController:navigationController];
I'm working on developing an app that uses the camera for a variety of different purposes. Right now, I'm struggling getting a tidbit of code to run when I launch the application:
UIImagePickerController *imageView = [[UIImagePickerController alloc]init];
imageView.delegate = self;
imageView.sourceType = UIImagePickerControllerSourceTypeCamera;
imageView.showsCameraControls = NO;
[self presentViewController:imageView animated:YES completion:NULL];
I need this to execute on the imageView UIView object at launch so when the application is opened, it goes straight to UIImagePickerController. Here is all of my code for the application:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)applicationDidBecomeActive
{
UIImagePickerController *imageView = [[UIImagePickerController alloc]init];
imageView.delegate = self;
imageView.sourceType = UIImagePickerControllerSourceTypeCamera;
imageView.showsCameraControls = NO;
[self presentViewController:imageView animated:YES completion:NULL];
}
#end
If you want to be informed in any controller, you should listen for UIApplicationDidBecomeActiveNotification or similar notifications.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(applicationDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
to unregister, do
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationDidBecomeActiveNotification
object:nil];
in dealloc or whenever you don't want to receive the notification anymore.
If you use storyboards, your app delegate should be like this
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
//…
#end
if you don't use storyboards your app delegate might be
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
self.window.rootViewController = [[ViewController alloc] init];
return YES;
}
//…
#end
and your view controller
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(applicationDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
- (void)applicationDidBecomeActive
{
UIImagePickerController *imageViewPickerController = [[UIImagePickerController alloc] init];
imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imageViewPickerController
animated:NO
completion:NULL];
}
#end
If you want code to run when you launch the app you should put it in:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
If you want the UIImagePickerController to be the first viewController presented you should set it as the window's rootViewController like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Set up imageView here
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
self.window.rootViewController = imageView;
return YES;
}
Use presentViewController if/when you want to present it from another viewController that is already onscreen.
I am trying to push the View.xib when the my UILocalNotification receives in my Appdelegate.m file. but my main root view controller is tab bar controller.
my code is not working which is as below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
application.applicationIconBadgeNumber = 0;
UILocalNotification *localNotif = [launchOptionsobjectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif)
{
NSLog(#"Recieved Notification %#\n",localNotif);
}
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_tabBarController = [[AKTabBarController alloc] initWithTabBarHeight: (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? 70 : 50];
[_tabBarController setViewControllers:[NSMutableArray arrayWithObjects:
navigationController,
navigationController2,
navigationController3,
nil]];
[_window setRootViewController:_tabBarController];
[_window makeKeyAndVisible];
return YES;
}
-(void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(#"in didReceiveLocalNotification");
StartViewController2Track *viewController = [[StartViewController2Track alloc]initWithNibName:NSStringFromClass([StartVie Controller2Track class]) bundle:nil];
// [self.window.rootViewController presentViewController:viewController animated:YES completion:nil ];
// [self.navcontrol pushViewController:viewController animated:YES];
[self.rootViewController.tabBarController.selectedViewController.navigationController [pushViewController:StartViewController2Track animated]];
}
Your rootviewcontroller is tabbarController. So you are trying to push from tabbarcontroller.tabbarcontroller and also selectedViewcontroller is also navigation controller. sot Try below..
[self.window.rootViewController.selectedViewController pushViewController:viewController animated:YES]];
I have already implemented JASidePanelController with storyboards way in a project and it works fine.
I have a Storyboard like this:
[NavigationController] -> [MySidePanelControllerViewController] [LoginVC] -> [HomeVC] -> [ListVC] -> [DescriptionVC]
And the swipe menu is in LoginVC that has Storyboard's ID centrerViewController.
Now I would like to have the swipe menu only in ListVC. How can I do that?
If I give Stroryboard ID centrerViewController to ListVC the application starts at ListVC, not at loginVC.
I have done the same thing but using MFSideMenuContainerViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:_rootNavController
leftMenuViewController:settingDrawerController
rightMenuViewController:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
[self.window setRootViewController:container];
}
and I have set my controller at application delegate and present the loginViewContrller as model view from
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self showLoginView];
}
- (void)showLoginView
{
UIViewController *topViewController = [self.navController topViewController];
if (![topViewController isKindOfClass:[LGLoginViewController class]]) {
[self.navController popToRootViewControllerAnimated:YES];
self.navController = nil;
LGLoginViewController* loginView = [[LGLoginViewController alloc] initWithNibName:#"LGLoginViewController"bundle:nil];
if (!self.navController) {
self.navController = [[UINavigationController alloc] initWithRootViewController:loginView];
} else {
[self.navController initWithRootViewController:loginView];
}
self.navController.delegate = self;
[self.window.rootViewController presentModalViewController:self.navController animated:NO];
}
}