Created
January 18, 2012 01:49
-
-
Save dcinzona/1630286 to your computer and use it in GitHub Desktop.
Fix for MKiCloudSync Crash
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
+(void) updateToiCloud:(NSNotification*) notificationObject { | |
NSMutableDictionary *dict = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] mutableCopy]; | |
for(NSString *keyName in dict.allKeys){ | |
NSString *keysToRemove = @"com.apple.audio.CoreAudio"; | |
NSInteger kL = keysToRemove.length; | |
if(keyName.length>kL){ | |
NSString *keySub = [keyName substringToIndex:kL]; | |
if([keySub isEqualToString:keysToRemove]){ | |
[dict removeObjectForKey:keyName]; | |
} | |
} | |
} | |
//NSLog(@"To iCloud: %@",dict.allKeys); | |
[dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { | |
[[NSUbiquitousKeyValueStore defaultStore] setObject:obj forKey:key]; | |
}]; | |
[[NSUbiquitousKeyValueStore defaultStore] synchronize]; | |
dict = nil; | |
} | |
+(void) updateFromiCloud:(NSNotification*) notificationObject { | |
NSUbiquitousKeyValueStore *iCloudStore = [NSUbiquitousKeyValueStore defaultStore]; | |
NSMutableDictionary *dict = [[iCloudStore dictionaryRepresentation] mutableCopy]; | |
for(NSString *keyName in dict.allKeys){ | |
NSString *keysToRemove = @"com.apple.audio.CoreAudio"; | |
NSInteger kL = keysToRemove.length; | |
if(keyName.length>kL){ | |
NSString *keySub = [keyName substringToIndex:kL]; | |
if([keySub isEqualToString:keysToRemove]){ | |
[dict removeObjectForKey:keyName]; | |
} | |
} | |
} | |
//NSLog(@"From iCloud: %@",dict.allKeys); | |
// prevent NSUserDefaultsDidChangeNotification from being posted while we update from iCloud | |
[[NSNotificationCenter defaultCenter] removeObserver:self | |
name:NSUserDefaultsDidChangeNotification | |
object:nil]; | |
[dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { | |
[[NSUserDefaults standardUserDefaults] setObject:obj forKey:key]; | |
}]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; | |
// enable NSUserDefaultsDidChangeNotification notifications again | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(updateToiCloud:) | |
name:NSUserDefaultsDidChangeNotification | |
object:nil]; | |
[[NSNotificationCenter defaultCenter] postNotificationName:kMKiCloudSyncNotification object:nil]; | |
dict = nil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment