Last active
March 10, 2016 15:52
-
-
Save craigmarvelley/6a5805fcec4e79db2b0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AppDelegate.h" | |
@interface AppDelegate () | |
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext; | |
@property (strong, nonatomic) GCDWebServer *webServer; | |
@end | |
@implementation AppDelegate | |
#pragma mark - UIApplicationDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
[self bootstrapApplication]; | |
return YES; | |
} | |
- (void)bootstrapApplication { | |
[self setUpHttpServer]; | |
if (![self userIsAuthenticated]) { | |
[self showLoginView]; | |
} else { | |
[self setUpDatabase:^{ | |
[self showHomeView]; | |
}]; | |
} | |
} | |
- (BOOL)userIsAuthenticated { | |
// Query keychain for authentication data | |
return YES; | |
} | |
- (void)showLogInView { | |
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LogIn" bundle:nil]; | |
LogInViewController *logInController = (LogInViewController *)[storyboard instantiateInitialViewController]; | |
// Set up more dependencies, store them on the delegate, and inject them | |
[self changeRootViewController:logInController]; | |
} | |
- (void)showHomeView { | |
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Home" bundle:nil]; | |
UISplitViewController *homeController = (UISplitViewController *)[storyboard instantiateInitialViewController]; | |
// Set up EVEN MORE dependencies, store them on the delegate, and inject them | |
[self changeRootViewController:homeController]; | |
} | |
- (void)changeRootViewController:(UIViewController *)viewController { | |
self.window.rootViewController = viewController; | |
} | |
- (void)authenticationStatusDidChange:(NSNotification *)notification { | |
if ([self userIsAuthenticated]) { | |
[self showHomeView]; | |
} else { | |
[self showLoginView]; | |
} | |
} | |
#pragma mark - | |
- (void)setUpWebServer { | |
if (!_webServer) { | |
_webServer = [[GCDWebServer alloc] init]; | |
[_webServer startWithPort:0 bonjourName:nil]; | |
} | |
} | |
#pragma mark - | |
- (void)setUpDatabase:(void (^)(void))callback { | |
// Create persistent store coordinator, managed object context, etc. in another thread then execute callback block | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment