Last active
December 31, 2015 19:38
-
-
Save keicoder/8034534 to your computer and use it in GitHub Desktop.
objective-c : 아이클라우드 설정 여부 체크 : didFinishLaunchingWithOptions 메소드
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
- (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