diff --git a/Externals/RMSharedPreferences/NSURL+RMApplicationGroup.m b/Externals/RMSharedPreferences/NSURL+RMApplicationGroup.m index f05eaa9..b99a292 100644 --- a/Externals/RMSharedPreferences/NSURL+RMApplicationGroup.m +++ b/Externals/RMSharedPreferences/NSURL+RMApplicationGroup.m @@ -23,38 +23,32 @@ #import "NSURL+RMApplicationGroup.h" -#import +#import #import @implementation NSURL (RMApplicationGroup) + (NSString *)defaultGroupContainerIdentifier { - SecTaskRef task = NULL; - - NSString *applicationGroupIdentifier = nil; - do { - task = SecTaskCreateFromSelf(kCFAllocatorDefault); - if (task == NULL) { - break; - } - - CFTypeRef applicationGroupIdentifiers = SecTaskCopyValueForEntitlement(task, CFSTR("com.apple.security.application-groups"), NULL); - if (applicationGroupIdentifiers == NULL || CFGetTypeID(applicationGroupIdentifiers) != CFArrayGetTypeID() || CFArrayGetCount(applicationGroupIdentifiers) == 0) { - break; - } - - CFTypeRef firstApplicationGroupIdentifier = CFArrayGetValueAtIndex(applicationGroupIdentifiers, 0); - if (CFGetTypeID(firstApplicationGroupIdentifier) != CFStringGetTypeID()) { - break; - } - - applicationGroupIdentifier = (__bridge NSString *)firstApplicationGroupIdentifier; - } while (0); - - if (task != NULL) { - CFRelease(task); - } + NSString* applicationGroupIdentifier = nil; + + SecCodeRef selfCode = NULL; + SecCodeCopySelf(kSecCSDefaultFlags, &selfCode); + + if (selfCode) + { + CFDictionaryRef cfDic = NULL; + SecCodeCopySigningInformation(selfCode, kSecCSRequirementInformation, &cfDic); + NSDictionary* signingDic = CFBridgingRelease(cfDic); + + NSDictionary* entitlementsDic = [signingDic objectForKey:@"entitlements-dict"]; + NSArray* appGroupsArray = [entitlementsDic objectForKey:@"com.apple.security.application-groups"]; + + if ([appGroupsArray isKindOfClass:[NSArray class]] && appGroupsArray.count > 0) + applicationGroupIdentifier = [appGroupsArray objectAtIndex:0]; + + CFRelease(selfCode); + } return applicationGroupIdentifier; } diff --git a/Externals/RMSharedPreferences/RMSharedPreferences.xcodeproj/project.pbxproj b/Externals/RMSharedPreferences/RMSharedPreferences.xcodeproj/project.pbxproj index daf1506..0e8a33e 100644 --- a/Externals/RMSharedPreferences/RMSharedPreferences.xcodeproj/project.pbxproj +++ b/Externals/RMSharedPreferences/RMSharedPreferences.xcodeproj/project.pbxproj @@ -206,7 +206,7 @@ }; buildConfigurationList = 6D74A055166373B400D70B8F /* Build configuration list for PBXProject "RMSharedPreferences" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = en-GB; + developmentRegion = "en-GB"; hasScannedForEncodings = 0; knownRegions = ( en, @@ -286,7 +286,7 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.8; + MACOSX_DEPLOYMENT_TARGET = 10.7.5; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; WARNING_CFLAGS = "-Wall"; @@ -311,7 +311,7 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.8; + MACOSX_DEPLOYMENT_TARGET = 10.7.5; SDKROOT = macosx; WARNING_CFLAGS = "-Wall"; }; diff --git a/Externals/RMSharedPreferences/RMSharedUserDefaults.h b/Externals/RMSharedPreferences/RMSharedUserDefaults.h index b0b45e7..dc54b97 100644 --- a/Externals/RMSharedPreferences/RMSharedUserDefaults.h +++ b/Externals/RMSharedPreferences/RMSharedUserDefaults.h @@ -37,6 +37,8 @@ */ - (id)initWithApplicationGroupIdentifier:(NSString *)applicationGroupIdentifier; +- (id) initWithSharedFileURL:(NSURL *)fileURL; + @end extern NSString * const RMSharedUserDefaultsDidChangeDefaultNameKey; diff --git a/Externals/RMSharedPreferences/RMSharedUserDefaults.m b/Externals/RMSharedPreferences/RMSharedUserDefaults.m index 114805f..5904180 100644 --- a/Externals/RMSharedPreferences/RMSharedUserDefaults.m +++ b/Externals/RMSharedPreferences/RMSharedUserDefaults.m @@ -74,11 +74,6 @@ + (void)resetStandardUserDefaults - (id)initWithApplicationGroupIdentifier:(NSString *)applicationGroupIdentifier { - self = [super initWithUser:nil]; - if (self == nil) { - return nil; - } - NSURL *applicationGroupLocation = [NSURL containerURLForSecurityApplicationGroupIdentifier:applicationGroupIdentifier]; if (applicationGroupLocation == nil) { @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"A default application group identifier cannot be found in the entitlements" userInfo:nil]; @@ -89,27 +84,49 @@ - (id)initWithApplicationGroupIdentifier:(NSString *)applicationGroupIdentifier [[NSFileManager defaultManager] createDirectoryAtURL:applicationGroupPreferencesLocation withIntermediateDirectories:YES attributes:nil error:NULL]; NSString *userDefaultsDictionaryFileName = applicationGroupIdentifier ? : [NSURL defaultGroupContainerIdentifier]; - _userDefaultsDictionaryLocation = [[applicationGroupPreferencesLocation URLByAppendingPathComponent:userDefaultsDictionaryFileName] URLByAppendingPathExtension:@"plist"]; - + NSURL* defaultsLocation = [[applicationGroupPreferencesLocation URLByAppendingPathComponent:userDefaultsDictionaryFileName] URLByAppendingPathExtension:@"plist"]; + + self = [self initWithSharedFileURL:defaultsLocation]; + if (self == nil) { + return nil; + } + + return self; +} + +- (id) initWithSharedFileURL:(NSURL *)fileURL +{ + self = [super initWithUser:nil]; + if (self == nil) { + return nil; + } + + if ( ! fileURL) { + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Shared defaults file name not specified" userInfo:nil]; + return nil; + } + + _userDefaultsDictionaryLocation = fileURL; + _updatedUserDefaultsDictionary = [NSMutableDictionary dictionary]; _registeredUserDefaultsDictionary = [NSMutableDictionary dictionary]; - + _accessorLock = [[NSRecursiveLock alloc] init]; _synchronizeLock = [[NSLock alloc] init]; - - NSString *queuePrefixName = [applicationGroupIdentifier stringByAppendingFormat:@".sharedpreferences"]; - + + NSString *queuePrefixName = [fileURL.lastPathComponent stringByAppendingFormat:@".sharedpreferences"]; + _fileCoordinationOperationQueue = [[NSOperationQueue alloc] init]; [_fileCoordinationOperationQueue setName:[queuePrefixName stringByAppendingFormat:@".filecoordination"]]; - + _synchronizationQueue = [[NSOperationQueue alloc] init]; [_synchronizationQueue setMaxConcurrentOperationCount:1]; [_synchronizationQueue setName:[queuePrefixName stringByAppendingFormat:@".synchronization"]]; - + [self _synchronize]; - + [NSFileCoordinator addFilePresenter:self]; - + return self; } @@ -130,15 +147,15 @@ - (id)objectForKey:(NSString *)defaultName __block id object = nil; [self _lock:[self accessorLock] criticalSection:^ { - object = [self updatedUserDefaultsDictionary][defaultName]; + object = [[self updatedUserDefaultsDictionary] objectForKey:defaultName]; if (object != nil) { return; } - object = [self userDefaultsDictionary][defaultName]; + object = [[self userDefaultsDictionary] objectForKey:defaultName]; if (object != nil) { return; } - object = [self registeredUserDefaultsDictionary][defaultName]; + object = [[self registeredUserDefaultsDictionary] objectForKey:defaultName]; }]; return object; @@ -351,7 +368,7 @@ - (NSDictionary *)__userDefaultsUpdates:(NSDictionary *)userDefaultsDictionary u NSSet *userDefaultsUpdatesFromDisk = [self _keyDiffsBetweenDictionaries:userDefaultsDictionary :[self userDefaultsDictionary]]; [userDefaultsUpdatesFromDisk enumerateObjectsUsingBlock:^ (NSString *defaultName, BOOL *stop) { - id value = userDefaultsDictionary[defaultName] ? : [NSNull null]; + id value = [userDefaultsDictionary objectForKey:defaultName] ? : [NSNull null]; [userDefaultsChanges setObject:value forKey:defaultName]; }]; diff --git a/Sample Application/Helper/RMHelperAppDelegate.m b/Sample Application/Helper/RMHelperAppDelegate.m index 4fa4c37..774c035 100644 --- a/Sample Application/Helper/RMHelperAppDelegate.m +++ b/Sample Application/Helper/RMHelperAppDelegate.m @@ -41,10 +41,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification - (void)preferencesDidUpdate:(NSNotification *)notification { - NSString *defaultName = [notification userInfo][RMSharedUserDefaultsDidChangeDefaultNameKey]; + NSString *defaultName = [[notification userInfo] objectForKey:RMSharedUserDefaultsDidChangeDefaultNameKey]; if ([defaultName isEqualToString:RMSharedPreferencesSomeTextDefaultKey]) { - NSString *text = [notification userInfo][RMSharedUserDefaultsDidChangeDefaulValueKey]; + NSString *text = [[notification userInfo]objectForKey:RMSharedUserDefaultsDidChangeDefaulValueKey]; [self _updateTextField:text]; } } diff --git a/Sample Application/SharedPreferences.xcodeproj/project.pbxproj b/Sample Application/SharedPreferences.xcodeproj/project.pbxproj index 4578aa0..0a56d90 100644 --- a/Sample Application/SharedPreferences.xcodeproj/project.pbxproj +++ b/Sample Application/SharedPreferences.xcodeproj/project.pbxproj @@ -467,9 +467,8 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.8; + MACOSX_DEPLOYMENT_TARGET = 10.7.5; ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; WARNING_CFLAGS = "-Wall"; }; name = Debug; @@ -492,8 +491,7 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.8; - SDKROOT = macosx; + MACOSX_DEPLOYMENT_TARGET = 10.7.5; WARNING_CFLAGS = "-Wall"; }; name = Release;