diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 1607ffdd9..f537ff8aa 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -106,10 +106,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // We need to this _after_ we set up logging but _before_ we do // anything else. - [self ensureMigrationToSharedData]; + [self ensureIsReadyForAppExtensions]; #if RELEASE - // ensureMigrationToSharedData may have changed the state of the logging + // ensureIsReadyForAppExtensions may have changed the state of the logging // preference, so honor that change if necessary. if (loggingIsEnabled && !OWSPreferences.loggingIsEnabled) { [DebugLogger.sharedLogger disableFileLogging]; @@ -189,9 +189,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; return YES; } -- (void)ensureMigrationToSharedData +- (void)ensureIsReadyForAppExtensions { - if ([OWSPreferences hasMigratedToSharedData]) { + if ([OWSPreferences isReadyForAppExtensions]) { return; } @@ -201,7 +201,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [OWSProfileManager migrateToSharedData]; [TSAttachmentStream migrateToSharedData]; - [OWSPreferences setHasMigratedToSharedData:YES]; + [OWSPreferences setIsReadyForAppExtensions:YES]; } - (void)startupLogging diff --git a/Signal/src/environment/OWSPreferences.h b/Signal/src/environment/OWSPreferences.h index 822f9fe4d..6a0cb1882 100644 --- a/Signal/src/environment/OWSPreferences.h +++ b/Signal/src/environment/OWSPreferences.h @@ -27,8 +27,8 @@ extern NSString *const OWSPreferencesKeyEnableDebugLog; #pragma mark - Specific Preferences -+ (BOOL)hasMigratedToSharedData; -+ (void)setHasMigratedToSharedData:(BOOL)value; ++ (BOOL)isReadyForAppExtensions; ++ (void)setIsReadyForAppExtensions:(BOOL)value; - (BOOL)getHasSentAMessage; - (void)setHasSentAMessage:(BOOL)enabled; diff --git a/Signal/src/environment/OWSPreferences.m b/Signal/src/environment/OWSPreferences.m index c7fa02d3c..8548715f8 100644 --- a/Signal/src/environment/OWSPreferences.m +++ b/Signal/src/environment/OWSPreferences.m @@ -23,7 +23,7 @@ NSString *const OWSPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled NSString *const OWSPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress"; NSString *const OWSPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView"; NSString *const OWSPreferencesKeyIOSUpgradeNagVersion = @"iOSUpgradeNagVersion"; -NSString *const OWSPreferencesKey_HasMigratedToSharedData = @"hasMigratedToSharedData"; +NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExtensions"; @implementation OWSPreferences @@ -60,9 +60,9 @@ NSString *const OWSPreferencesKey_HasMigratedToSharedData = @"hasMigratedToShare #pragma mark - Specific Preferences -+ (BOOL)hasMigratedToSharedData ++ (BOOL)isReadyForAppExtensions { - NSNumber *preference = [NSUserDefaults.appUserDefaults objectForKey:OWSPreferencesKey_HasMigratedToSharedData]; + NSNumber *preference = [NSUserDefaults.appUserDefaults objectForKey:OWSPreferencesKey_IsReadyForAppExtensions]; if (preference) { return [preference boolValue]; @@ -71,9 +71,9 @@ NSString *const OWSPreferencesKey_HasMigratedToSharedData = @"hasMigratedToShare } } -+ (void)setHasMigratedToSharedData:(BOOL)value ++ (void)setIsReadyForAppExtensions:(BOOL)value { - [NSUserDefaults.appUserDefaults setObject:@(value) forKey:OWSPreferencesKey_HasMigratedToSharedData]; + [NSUserDefaults.appUserDefaults setObject:@(value) forKey:OWSPreferencesKey_IsReadyForAppExtensions]; [NSUserDefaults.appUserDefaults synchronize]; } diff --git a/SignalServiceKit/src/TSConstants.h b/SignalServiceKit/src/TSConstants.h index cefd281a0..717e2e0fc 100644 --- a/SignalServiceKit/src/TSConstants.h +++ b/SignalServiceKit/src/TSConstants.h @@ -57,6 +57,8 @@ typedef enum { kSMSVerification, kPhoneNumberVerification } VerificationTranspor #define textSecureSetProfileNameAPIFormat @"v1/profile/name/%@" #define textSecureProfileAvatarFormAPI @"v1/profile/form/avatar" +#define SignalApplicationGroup @"group.org.whispersystems.signal.group" + #pragma mark Push RegistrationSpecific Constants typedef NS_ENUM(NSInteger, TSPushRegistrationError) { TSPushRegistrationErrorNetwork, diff --git a/SignalServiceKit/src/Util/NSUserDefaults+OWS.m b/SignalServiceKit/src/Util/NSUserDefaults+OWS.m index 1bff0e3e3..923ada8e1 100644 --- a/SignalServiceKit/src/Util/NSUserDefaults+OWS.m +++ b/SignalServiceKit/src/Util/NSUserDefaults+OWS.m @@ -3,6 +3,7 @@ // #import "NSUserDefaults+OWS.h" +#import "TSConstants.h" NS_ASSUME_NONNULL_BEGIN @@ -10,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN + (NSUserDefaults *)appUserDefaults { - return [[NSUserDefaults alloc] initWithSuiteName:@"group.org.whispersystems.signal.group"]; + return [[NSUserDefaults alloc] initWithSuiteName:SignalApplicationGroup]; } + (void)migrateToSharedUserDefaults diff --git a/SignalServiceKit/src/Util/OWSFileSystem.m b/SignalServiceKit/src/Util/OWSFileSystem.m index 1d77559ad..551387b93 100644 --- a/SignalServiceKit/src/Util/OWSFileSystem.m +++ b/SignalServiceKit/src/Util/OWSFileSystem.m @@ -3,6 +3,7 @@ // #import "OWSFileSystem.h" +#import "TSConstants.h" NS_ASSUME_NONNULL_BEGIN @@ -38,8 +39,8 @@ NS_ASSUME_NONNULL_BEGIN + (NSString *)appSharedDataDirectoryPath { - NSURL *groupContainerDirectoryURL = [[NSFileManager defaultManager] - containerURLForSecurityApplicationGroupIdentifier:@"group.org.whispersystems.signal.group"]; + NSURL *groupContainerDirectoryURL = + [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:SignalApplicationGroup]; return [groupContainerDirectoryURL path]; } @@ -52,7 +53,8 @@ NS_ASSUME_NONNULL_BEGIN return; } if ([fileManager fileExistsAtPath:newFilePath]) { - DDLogError(@""); + OWSFail( + @"%@ Can't move file from %@ to %@; destination already exists.", self.logTag, oldFilePath, newFilePath); return; } @@ -62,11 +64,11 @@ NS_ASSUME_NONNULL_BEGIN BOOL success = [fileManager moveItemAtPath:oldFilePath toPath:newFilePath error:&error]; if (!success || error) { NSString *errorDescription = - [NSString stringWithFormat:@"%@ Could not move database file from %@ to %@, error: %@", - self.logTag, - oldFilePath, - newFilePath, - error]; + [NSString stringWithFormat:@"%@ Could not move file or directory from %@ to %@, error: %@", + self.logTag, + oldFilePath, + newFilePath, + error]; OWSFail(@"%@", errorDescription); [NSException raise:exceptionName format:@"%@", errorDescription]; }