Skip to content

Instantly share code, notes, and snippets.

@Raztor0
Created July 4, 2016 03:10
Show Gist options
  • Save Raztor0/1fe06b6ff1d2fecb8c9cbdc09611b42e to your computer and use it in GitHub Desktop.
Save Raztor0/1fe06b6ff1d2fecb8c9cbdc09611b42e to your computer and use it in GitHub Desktop.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ubiquitousKeyValueStoreDidChange:) name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification object:[NSUbiquitousKeyValueStore defaultStore]];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
return YES;
}
#pragma mark - NSNotifications
- (void)ubiquitousKeyValueStoreDidChange:(NSNotification*)notification {
NSUbiquitousKeyValueStore *ubiquitousKeyValueStore = notification.object;
NSString *UUID;
if ((UUID = [ubiquitousKeyValueStore stringForKey:@"UUID"])) {
NSLog(@"Got UUID: %@", UUID);
} else {
UUID = [[NSUUID UUID] UUIDString];
[ubiquitousKeyValueStore setString:UUID forKey:@"UUID"];
NSLog(@"Set UUID: %@", UUID);
}
[ubiquitousKeyValueStore synchronize];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment