I have an application that implements Facebook login at startup using code very similar to this: Facebook Scrumptious Tutorial , with the exception of Storyboard.
The main point of the code is that when the application starts, the application delegate checks if you are already logged in, and if you use it directly to the main view, and if not, it asks for the main view, enter the login so that the user can log in the system.
I already solved my other problem, having the opportunity to tell the main view in the storyboard, to present another view, getting the main view from the hierarchy of views, and then calling segue in the view. Everything works fine, however I have one last problem:
As far as I know, it is assumed that the didFinishLaunchingWithOptions application will be called after the storyboard is fully loaded. However, in my code, if I try to tell the main view about the view of another view, it gives me an error basically saying that it is not loaded yet (Warning: attempt to present <QLoginViewController: 0x955c020> on <UINavigationController: 0xa28c6e0> whose look is not in hierarchy of windows!).
If I tell him to submit a presentation after a delay, however:
[self performSelector:@selector(showLoginViewAnimated:) withObject:NO afterDelay:.001];
( showLoginViewAnimated: , ), .
- , , ? , , , , ...
appDelegate didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.navigationController = (UINavigationController *)self.window.rootViewController;
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:255.0/255.0 green:128.0/255.0 blue:60.0/255.0 alpha:1.0]];
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
[self openSession];
} else {
if ([self.navigationController isViewLoaded]) {
[self showLoginViewAnimated:NO];
}
else {
[self performSelector:@selector(showLoginViewAnimated:) withObject:NO afterDelay:.001];
}
}
return YES;
}
showLoginViewAnimated: code:
- (void)showLoginViewAnimated:(BOOL)animated
{
UIViewController *topViewController = [self.navigationController topViewController];
UIViewController *presentedViewController = [topViewController presentedViewController];
if (![presentedViewController isKindOfClass:[QLoginViewController class]]) {
if (animated) {
[topViewController performSegueWithIdentifier:@"ShowLoginViewAnimated" sender:self];
}
else {
[topViewController performSegueWithIdentifier:@"ShowLoginViewStatic" sender:self];
}
}
else {
QLoginViewController *loginViewController = (QLoginViewController *)presentedViewController;
[loginViewController loginFailed];
}
}
, , showLoginViewAnimated: didFinishLaunchingWithOptions, :
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
, 100% , , , . , , didFinishLaunchingWithOptions , , , , , , ? ...
?
!
: , - , . (BOOL) showLoginView , - ( ).
(-) appDelegate didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[FBLViewController alloc] initWithNibName:@"FBLViewController" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
[self openSession];
}
else {
[self showLoginView];
}
return YES;
}
showLoginView (non-storyboard):
- (void)showLoginView
{
UIViewController *topViewController = [self.navController topViewController];
UIViewController *presentedViewController = [topViewController presentedViewController];
if (![presentedViewController isKindOfClass:[FBLLoginViewController class]]) {
FBLLoginViewController *loginViewController = [[FBLLoginViewController alloc] initWithNibName:@"FBLLoginViewController" bundle:nil];
loginViewController.delegate = self;
[topViewController presentViewController:loginViewController animated:NO completion:nil];
}
else {
FBLLoginViewController *loginViewController = (FBLLoginViewController *)presentedViewController;
[loginViewController loginFailed];
}
}