Skip to content

Instantly share code, notes, and snippets.

@keicoder
Last active December 31, 2015 19:38
Show Gist options
  • Save keicoder/8034534 to your computer and use it in GitHub Desktop.
Save keicoder/8034534 to your computer and use it in GitHub Desktop.
objective-c : 아이클라우드 설정 여부 체크 : didFinishLaunchingWithOptions 메소드
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSUbiquitousKeyValueStore *kvoStore =
[NSUbiquitousKeyValueStore defaultStore];
NSString *stringValue = @"My String";
NSString *stringValueKey = @"MyStringKey";
BOOL boolValue = YES;
NSString *boolValueKey = @"MyBoolKey";
BOOL mustSynchronize = NO;
if ([[kvoStore stringForKey:stringValueKey] length] == 0){
NSLog(@"Could not find the string value in iCloud. Setting...");
[kvoStore setString:stringValue
forKey:stringValueKey];
mustSynchronize = YES;
} else {
NSLog(@"Found the string in iCloud, getting...");
stringValue = [kvoStore stringForKey:stringValueKey];
}
if ([kvoStore boolForKey:boolValueKey] == NO){
NSLog(@"Could not find the boolean value in iCloud. Setting...");
[kvoStore setBool:boolValue
forKey:boolValueKey];
mustSynchronize = YES;
} else {
NSLog(@"Found the boolean in iCloud, getting...");
boolValue = [kvoStore boolForKey:boolValueKey];
}
if (mustSynchronize){
if ([kvoStore synchronize]){
NSLog(@"Successfully synchronized with iCloud.");
} else {
NSLog(@"Failed to synchronize with iCloud.");
}
}
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment