Handle iCloud status.
This commit is contained in:
parent
c7f5047056
commit
e19b457cb3
|
@ -27,6 +27,17 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@implementation OWSBackupSettingsViewController
|
@implementation OWSBackupSettingsViewController
|
||||||
|
|
||||||
|
#pragma mark - Dependencies
|
||||||
|
|
||||||
|
- (OWSBackup *)backup
|
||||||
|
{
|
||||||
|
OWSAssertDebug(AppEnvironment.shared.backup);
|
||||||
|
|
||||||
|
return AppEnvironment.shared.backup;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
|
||||||
- (void)viewDidLoad
|
- (void)viewDidLoad
|
||||||
{
|
{
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
@ -61,7 +72,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
- (void)updateICloudStatus
|
- (void)updateICloudStatus
|
||||||
{
|
{
|
||||||
__weak OWSBackupSettingsViewController *weakSelf = self;
|
__weak OWSBackupSettingsViewController *weakSelf = self;
|
||||||
[[OWSBackupAPI checkCloudKitAccessObjc]
|
[[self.backup checkCloudKitAccess]
|
||||||
.then(^{
|
.then(^{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
weakSelf.iCloudError = nil;
|
weakSelf.iCloudError = nil;
|
||||||
|
|
|
@ -24,6 +24,13 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
return SSKEnvironment.shared.tsAccountManager;
|
return SSKEnvironment.shared.tsAccountManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (OWSBackup *)backup
|
||||||
|
{
|
||||||
|
OWSAssertDebug(AppEnvironment.shared.backup);
|
||||||
|
|
||||||
|
return AppEnvironment.shared.backup;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Factory Methods
|
#pragma mark - Factory Methods
|
||||||
|
|
||||||
- (NSString *)name
|
- (NSString *)name
|
||||||
|
@ -81,7 +88,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
OWSAssertDebug(success);
|
OWSAssertDebug(success);
|
||||||
|
|
||||||
NSString *recipientId = self.tsAccountManager.localNumber;
|
NSString *recipientId = self.tsAccountManager.localNumber;
|
||||||
[[OWSBackupAPI checkCloudKitAccessObjc]
|
[[self.backup checkCloudKitAccess]
|
||||||
.then(^{
|
.then(^{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[OWSBackupAPI saveTestFileToCloudWithRecipientId:recipientId
|
[OWSBackupAPI saveTestFileToCloudWithRecipientId:recipientId
|
||||||
|
|
|
@ -26,6 +26,7 @@ NSString *NSStringForBackupImportState(OWSBackupState state);
|
||||||
|
|
||||||
NSArray<NSString *> *MiscCollectionsToBackup(void);
|
NSArray<NSString *> *MiscCollectionsToBackup(void);
|
||||||
|
|
||||||
|
@class AnyPromise;
|
||||||
@class OWSBackupIO;
|
@class OWSBackupIO;
|
||||||
@class TSAttachmentPointer;
|
@class TSAttachmentPointer;
|
||||||
@class TSThread;
|
@class TSThread;
|
||||||
|
@ -71,7 +72,9 @@ NSArray<NSString *> *MiscCollectionsToBackup(void);
|
||||||
|
|
||||||
- (void)allRecipientIdsWithManifestsInCloud:(OWSBackupStringListBlock)success failure:(OWSBackupErrorBlock)failure;
|
- (void)allRecipientIdsWithManifestsInCloud:(OWSBackupStringListBlock)success failure:(OWSBackupErrorBlock)failure;
|
||||||
|
|
||||||
- (void)checkCanExportBackup:(OWSBackupBoolBlock)success failure:(OWSBackupErrorBlock)failure;
|
- (AnyPromise *)checkCloudKitAccess;
|
||||||
|
|
||||||
|
- (AnyPromise *)checkCanExportBackup;
|
||||||
|
|
||||||
- (void)checkCanImportBackup:(OWSBackupBoolBlock)success failure:(OWSBackupErrorBlock)failure;
|
- (void)checkCanImportBackup:(OWSBackupBoolBlock)success failure:(OWSBackupErrorBlock)failure;
|
||||||
|
|
||||||
|
|
|
@ -410,23 +410,25 @@ NSArray<NSString *> *MiscCollectionsToBackup(void)
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)checkCanExportBackup:(OWSBackupBoolBlock)success failure:(OWSBackupErrorBlock)failure
|
- (AnyPromise *)checkCanExportBackup
|
||||||
|
{
|
||||||
|
return [self checkCloudKitAccess];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (AnyPromise *)checkCloudKitAccess
|
||||||
{
|
{
|
||||||
OWSAssertIsOnMainThread();
|
OWSAssertIsOnMainThread();
|
||||||
|
|
||||||
OWSLogInfo(@"");
|
OWSLogInfo(@"");
|
||||||
|
|
||||||
void (^failWithUnexpectedError)(void) = ^{
|
AnyPromise * (^failWithUnexpectedError)(void) = ^{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
NSError *error = [NSError errorWithDomain:OWSBackupErrorDomain
|
||||||
NSError *error =
|
code:1
|
||||||
[NSError errorWithDomain:OWSBackupErrorDomain
|
userInfo:@{
|
||||||
code:1
|
NSLocalizedDescriptionKey : NSLocalizedString(@"BACKUP_UNEXPECTED_ERROR",
|
||||||
userInfo:@{
|
@"Error shown when backup fails due to an unexpected error.")
|
||||||
NSLocalizedDescriptionKey : NSLocalizedString(@"BACKUP_UNEXPECTED_ERROR",
|
}];
|
||||||
@"Error shown when backup fails due to an unexpected error.")
|
return [AnyPromise promiseWithValue:error];
|
||||||
}];
|
|
||||||
failure(error);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!self.tsAccountManager.isRegisteredAndReady) {
|
if (!self.tsAccountManager.isRegisteredAndReady) {
|
||||||
|
@ -439,17 +441,7 @@ NSArray<NSString *> *MiscCollectionsToBackup(void)
|
||||||
return failWithUnexpectedError();
|
return failWithUnexpectedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[OWSBackupAPI checkCloudKitAccessObjc]
|
return [[OWSBackupAPI checkCloudKitAccessObjc] retainUntilComplete];
|
||||||
.then(^{
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
success(YES);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(^(NSError *error) {
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
failure(error);
|
|
||||||
});
|
|
||||||
}) retainUntilComplete];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)checkCanImportBackup:(OWSBackupBoolBlock)success failure:(OWSBackupErrorBlock)failure
|
- (void)checkCanImportBackup:(OWSBackupBoolBlock)success failure:(OWSBackupErrorBlock)failure
|
||||||
|
@ -481,17 +473,25 @@ NSArray<NSString *> *MiscCollectionsToBackup(void)
|
||||||
return failWithUnexpectedError();
|
return failWithUnexpectedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
[OWSBackupAPI checkForManifestInCloudWithRecipientId:recipientId
|
[[OWSBackupAPI checkCloudKitAccessObjc]
|
||||||
success:^(BOOL value) {
|
.then(^{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
[OWSBackupAPI checkForManifestInCloudWithRecipientId:recipientId
|
||||||
success(value);
|
success:^(BOOL value) {
|
||||||
});
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
}
|
success(value);
|
||||||
failure:^(NSError *error) {
|
});
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
}
|
||||||
failure(error);
|
failure:^(NSError *error) {
|
||||||
});
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
}];
|
failure(error);
|
||||||
|
});
|
||||||
|
}];
|
||||||
|
})
|
||||||
|
.catch(^(NSError *error) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
failure(error);
|
||||||
|
});
|
||||||
|
}) retainUntilComplete];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tryToImportBackup
|
- (void)tryToImportBackup
|
||||||
|
|
|
@ -700,16 +700,6 @@ import PromiseKit
|
||||||
return promise
|
return promise
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
|
||||||
public class func checkCloudKitAccessAndPresentAnyError() {
|
|
||||||
checkCloudKitAccess()
|
|
||||||
.catch({ (error) in
|
|
||||||
let errorMessage = self.errorMessage(forCloudKitAccessError: error)
|
|
||||||
OWSAlerts.showErrorAlert(message: errorMessage)
|
|
||||||
})
|
|
||||||
.retainUntilComplete()
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public class func errorMessage(forCloudKitAccessError error: Error) -> String {
|
public class func errorMessage(forCloudKitAccessError error: Error) -> String {
|
||||||
if let backupError = error as? BackupError {
|
if let backupError = error as? BackupError {
|
||||||
|
|
|
@ -328,6 +328,13 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
return SSKEnvironment.shared.primaryStorage;
|
return SSKEnvironment.shared.primaryStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (OWSBackup *)backup
|
||||||
|
{
|
||||||
|
OWSAssertDebug(AppEnvironment.shared.backup);
|
||||||
|
|
||||||
|
return AppEnvironment.shared.backup;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
- (void)startAsync
|
- (void)startAsync
|
||||||
|
@ -341,7 +348,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
[self updateProgressWithDescription:nil progress:nil];
|
[self updateProgressWithDescription:nil progress:nil];
|
||||||
|
|
||||||
__weak OWSBackupExportJob *weakSelf = self;
|
__weak OWSBackupExportJob *weakSelf = self;
|
||||||
[[OWSBackupAPI checkCloudKitAccessObjc]
|
[[self.backup checkCloudKitAccess]
|
||||||
.then(^{
|
.then(^{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[weakSelf start];
|
[weakSelf start];
|
||||||
|
|
|
@ -57,6 +57,13 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
|
||||||
return SSKEnvironment.shared.tsAccountManager;
|
return SSKEnvironment.shared.tsAccountManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (OWSBackup *)backup
|
||||||
|
{
|
||||||
|
OWSAssertDebug(AppEnvironment.shared.backup);
|
||||||
|
|
||||||
|
return AppEnvironment.shared.backup;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
- (void)startAsync
|
- (void)startAsync
|
||||||
|
@ -70,7 +77,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
|
||||||
[self updateProgressWithDescription:nil progress:nil];
|
[self updateProgressWithDescription:nil progress:nil];
|
||||||
|
|
||||||
__weak OWSBackupImportJob *weakSelf = self;
|
__weak OWSBackupImportJob *weakSelf = self;
|
||||||
[[OWSBackupAPI checkCloudKitAccessObjc]
|
[[self.backup checkCloudKitAccess]
|
||||||
.then(^{
|
.then(^{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[weakSelf start];
|
[weakSelf start];
|
||||||
|
|
|
@ -243,7 +243,7 @@
|
||||||
"BACKUP_RESTORE_STATUS" = "Status";
|
"BACKUP_RESTORE_STATUS" = "Status";
|
||||||
|
|
||||||
/* Error shown when backup fails due to an unexpected error. */
|
/* Error shown when backup fails due to an unexpected error. */
|
||||||
"BACKUP_UNEXPECTED_ERROR" = "Unexpected Error";
|
"BACKUP_UNEXPECTED_ERROR" = "Unexpected Backup Error";
|
||||||
|
|
||||||
/* An explanation of the consequences of blocking a group. */
|
/* An explanation of the consequences of blocking a group. */
|
||||||
"BLOCK_GROUP_BEHAVIOR_EXPLANATION" = "You will no longer receive messages or updates from this group.";
|
"BLOCK_GROUP_BEHAVIOR_EXPLANATION" = "You will no longer receive messages or updates from this group.";
|
||||||
|
|
|
@ -11,12 +11,14 @@ public extension AnyPromise {
|
||||||
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
func retainUntilComplete() {
|
@discardableResult
|
||||||
|
func retainUntilComplete() -> AnyPromise {
|
||||||
var retainCycle: AnyPromise? = self
|
var retainCycle: AnyPromise? = self
|
||||||
_ = self.ensure {
|
_ = self.ensure {
|
||||||
assert(retainCycle != nil)
|
assert(retainCycle != nil)
|
||||||
retainCycle = nil
|
retainCycle = nil
|
||||||
}
|
}
|
||||||
|
return self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,12 +27,14 @@ public extension PMKFinalizer {
|
||||||
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
||||||
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
||||||
*/
|
*/
|
||||||
func retainUntilComplete() {
|
@discardableResult
|
||||||
|
func retainUntilComplete() -> PMKFinalizer {
|
||||||
var retainCycle: PMKFinalizer? = self
|
var retainCycle: PMKFinalizer? = self
|
||||||
_ = self.finally {
|
_ = self.finally {
|
||||||
assert(retainCycle != nil)
|
assert(retainCycle != nil)
|
||||||
retainCycle = nil
|
retainCycle = nil
|
||||||
}
|
}
|
||||||
|
return self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,12 +43,14 @@ public extension Promise {
|
||||||
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
||||||
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
||||||
*/
|
*/
|
||||||
func retainUntilComplete() {
|
@discardableResult
|
||||||
|
func retainUntilComplete() -> Promise<T> {
|
||||||
var retainCycle: Promise<T>? = self
|
var retainCycle: Promise<T>? = self
|
||||||
_ = self.ensure {
|
_ = self.ensure {
|
||||||
assert(retainCycle != nil)
|
assert(retainCycle != nil)
|
||||||
retainCycle = nil
|
retainCycle = nil
|
||||||
}
|
}
|
||||||
|
return self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,11 +59,13 @@ public extension Guarantee {
|
||||||
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
||||||
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
||||||
*/
|
*/
|
||||||
func retainUntilComplete() {
|
@discardableResult
|
||||||
|
func retainUntilComplete() -> Guarantee<T> {
|
||||||
var retainCycle: Guarantee<T>? = self
|
var retainCycle: Guarantee<T>? = self
|
||||||
_ = self.done { _ in
|
_ = self.done { _ in
|
||||||
assert(retainCycle != nil)
|
assert(retainCycle != nil)
|
||||||
retainCycle = nil
|
retainCycle = nil
|
||||||
}
|
}
|
||||||
|
return self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue