Skip to content

Instantly share code, notes, and snippets.

@rickmak
Created June 20, 2016 05:05
Show Gist options
  • Save rickmak/54584ed79328ffdca1daf84f7aa1a3bc to your computer and use it in GitHub Desktop.
Save rickmak/54584ed79328ffdca1daf84f7aa1a3bc to your computer and use it in GitHub Desktop.
How to load the previously logged in SKYKit
- (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