Created
June 20, 2016 05:05
-
-
Save rickmak/54584ed79328ffdca1daf84f7aa1a3bc to your computer and use it in GitHub Desktop.
How to load the previously logged in SKYKit
This file contains 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
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; | |
SKYContainer *container = [SKYContainer defaultContainer]; | |
[container configAddress:SKYGEAR_ENDPOINT]; | |
[container configureWithAPIKey:SKYGEAR_APIKEY]; | |
[container loadAccessCurrentUserRecordIDAndAccessToken]; | |
container.delegate = self; | |
void (^registerDevice)(void) = ^void(void) { | |
[[SKYContainer defaultContainer] registerDeviceCompletionHandler:^(NSString *deviceID, NSError *error) { | |
if (error) { | |
NSLog(@"Failed to register device: %@", error); | |
return; | |
} | |
}]; | |
}; | |
if (container.currentUserRecordID) { | |
registerDevice(); | |
} | |
[[NSNotificationCenter defaultCenter] addObserverForName:SKYContainerDidChangeCurrentUserNotification | |
object:nil | |
queue:[NSOperationQueue mainQueue] | |
usingBlock:^(NSNotification * note) { | |
registerDevice(); | |
}]; | |
if (!container.currentUserRecordID) { | |
typeof(self) __weak weakSelf = self; | |
[self.window setRootViewController:[[RegisterationNavigationController alloc] initWithCompletion:^{ | |
[weakSelf.window.rootViewController presentViewController:[MainViewController sharedInstance] animated:YES completion:nil]; | |
}]]; | |
} else { | |
[self.window setRootViewController:[MainViewController sharedInstance]]; | |
} | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment