Handle iCloud status.
This commit is contained in:
parent
c7f5047056
commit
e19b457cb3
|
@ -27,6 +27,17 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@implementation OWSBackupSettingsViewController
|
||||
|
||||
#pragma mark - Dependencies
|
||||
|
||||
- (OWSBackup *)backup
|
||||
{
|
||||
OWSAssertDebug(AppEnvironment.shared.backup);
|
||||
|
||||
return AppEnvironment.shared.backup;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
@ -61,7 +72,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
- (void)updateICloudStatus
|
||||
{
|
||||
__weak OWSBackupSettingsViewController *weakSelf = self;
|
||||
[[OWSBackupAPI checkCloudKitAccessObjc]
|
||||
[[self.backup checkCloudKitAccess]
|
||||
.then(^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
weakSelf.iCloudError = nil;
|
||||
|
|
|
@ -24,6 +24,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return SSKEnvironment.shared.tsAccountManager;
|
||||
}
|
||||
|
||||
+ (OWSBackup *)backup
|
||||
{
|
||||
OWSAssertDebug(AppEnvironment.shared.backup);
|
||||
|
||||
return AppEnvironment.shared.backup;
|
||||
}
|
||||
|
||||
#pragma mark - Factory Methods
|
||||
|
||||
- (NSString *)name
|
||||
|
@ -81,7 +88,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSAssertDebug(success);
|
||||
|
||||
NSString *recipientId = self.tsAccountManager.localNumber;
|
||||
[[OWSBackupAPI checkCloudKitAccessObjc]
|
||||
[[self.backup checkCloudKitAccess]
|
||||
.then(^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[OWSBackupAPI saveTestFileToCloudWithRecipientId:recipientId
|
||||
|
|
|
@ -26,6 +26,7 @@ NSString *NSStringForBackupImportState(OWSBackupState state);
|
|||
|
||||
NSArray<NSString *> *MiscCollectionsToBackup(void);
|
||||
|
||||
@class AnyPromise;
|
||||
@class OWSBackupIO;
|
||||
@class TSAttachmentPointer;
|
||||
@class TSThread;
|
||||
|
@ -71,7 +72,9 @@ NSArray<NSString *> *MiscCollectionsToBackup(void);
|
|||
|
||||
- (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;
|
||||
|
||||
|
|
|
@ -410,23 +410,25 @@ NSArray<NSString *> *MiscCollectionsToBackup(void)
|
|||
}];
|
||||
}
|
||||
|
||||
- (void)checkCanExportBackup:(OWSBackupBoolBlock)success failure:(OWSBackupErrorBlock)failure
|
||||
- (AnyPromise *)checkCanExportBackup
|
||||
{
|
||||
return [self checkCloudKitAccess];
|
||||
}
|
||||
|
||||
- (AnyPromise *)checkCloudKitAccess
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
OWSLogInfo(@"");
|
||||
|
||||
void (^failWithUnexpectedError)(void) = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSError *error =
|
||||
[NSError errorWithDomain:OWSBackupErrorDomain
|
||||
code:1
|
||||
userInfo:@{
|
||||
NSLocalizedDescriptionKey : NSLocalizedString(@"BACKUP_UNEXPECTED_ERROR",
|
||||
@"Error shown when backup fails due to an unexpected error.")
|
||||
}];
|
||||
failure(error);
|
||||
});
|
||||
AnyPromise * (^failWithUnexpectedError)(void) = ^{
|
||||
NSError *error = [NSError errorWithDomain:OWSBackupErrorDomain
|
||||
code:1
|
||||
userInfo:@{
|
||||
NSLocalizedDescriptionKey : NSLocalizedString(@"BACKUP_UNEXPECTED_ERROR",
|
||||
@"Error shown when backup fails due to an unexpected error.")
|
||||
}];
|
||||
return [AnyPromise promiseWithValue:error];
|
||||
};
|
||||
|
||||
if (!self.tsAccountManager.isRegisteredAndReady) {
|
||||
|
@ -439,17 +441,7 @@ NSArray<NSString *> *MiscCollectionsToBackup(void)
|
|||
return failWithUnexpectedError();
|
||||
}
|
||||
|
||||
[[OWSBackupAPI checkCloudKitAccessObjc]
|
||||
.then(^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
success(YES);
|
||||
});
|
||||
})
|
||||
.catch(^(NSError *error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
failure(error);
|
||||
});
|
||||
}) retainUntilComplete];
|
||||
return [[OWSBackupAPI checkCloudKitAccessObjc] retainUntilComplete];
|
||||
}
|
||||
|
||||
- (void)checkCanImportBackup:(OWSBackupBoolBlock)success failure:(OWSBackupErrorBlock)failure
|
||||
|
@ -481,17 +473,25 @@ NSArray<NSString *> *MiscCollectionsToBackup(void)
|
|||
return failWithUnexpectedError();
|
||||
}
|
||||
|
||||
[OWSBackupAPI checkForManifestInCloudWithRecipientId:recipientId
|
||||
success:^(BOOL value) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
success(value);
|
||||
});
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
failure(error);
|
||||
});
|
||||
}];
|
||||
[[OWSBackupAPI checkCloudKitAccessObjc]
|
||||
.then(^{
|
||||
[OWSBackupAPI checkForManifestInCloudWithRecipientId:recipientId
|
||||
success:^(BOOL value) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
success(value);
|
||||
});
|
||||
}
|
||||
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
|
||||
|
|
|
@ -700,16 +700,6 @@ import PromiseKit
|
|||
return promise
|
||||
}
|
||||
|
||||
@objc
|
||||
public class func checkCloudKitAccessAndPresentAnyError() {
|
||||
checkCloudKitAccess()
|
||||
.catch({ (error) in
|
||||
let errorMessage = self.errorMessage(forCloudKitAccessError: error)
|
||||
OWSAlerts.showErrorAlert(message: errorMessage)
|
||||
})
|
||||
.retainUntilComplete()
|
||||
}
|
||||
|
||||
@objc
|
||||
public class func errorMessage(forCloudKitAccessError error: Error) -> String {
|
||||
if let backupError = error as? BackupError {
|
||||
|
|
|
@ -328,6 +328,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return SSKEnvironment.shared.primaryStorage;
|
||||
}
|
||||
|
||||
- (OWSBackup *)backup
|
||||
{
|
||||
OWSAssertDebug(AppEnvironment.shared.backup);
|
||||
|
||||
return AppEnvironment.shared.backup;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)startAsync
|
||||
|
@ -341,7 +348,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[self updateProgressWithDescription:nil progress:nil];
|
||||
|
||||
__weak OWSBackupExportJob *weakSelf = self;
|
||||
[[OWSBackupAPI checkCloudKitAccessObjc]
|
||||
[[self.backup checkCloudKitAccess]
|
||||
.then(^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf start];
|
||||
|
|
|
@ -57,6 +57,13 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
|
|||
return SSKEnvironment.shared.tsAccountManager;
|
||||
}
|
||||
|
||||
- (OWSBackup *)backup
|
||||
{
|
||||
OWSAssertDebug(AppEnvironment.shared.backup);
|
||||
|
||||
return AppEnvironment.shared.backup;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)startAsync
|
||||
|
@ -70,7 +77,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
|
|||
[self updateProgressWithDescription:nil progress:nil];
|
||||
|
||||
__weak OWSBackupImportJob *weakSelf = self;
|
||||
[[OWSBackupAPI checkCloudKitAccessObjc]
|
||||
[[self.backup checkCloudKitAccess]
|
||||
.then(^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf start];
|
||||
|
|
|
@ -243,7 +243,7 @@
|
|||
"BACKUP_RESTORE_STATUS" = "Status";
|
||||
|
||||
/* 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. */
|
||||
"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.
|
||||
*/
|
||||
@objc
|
||||
func retainUntilComplete() {
|
||||
@discardableResult
|
||||
func retainUntilComplete() -> AnyPromise {
|
||||
var retainCycle: AnyPromise? = self
|
||||
_ = self.ensure {
|
||||
assert(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
|
||||
* 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
|
||||
_ = self.finally {
|
||||
assert(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
|
||||
* 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
|
||||
_ = self.ensure {
|
||||
assert(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
|
||||
* 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
|
||||
_ = self.done { _ in
|
||||
assert(retainCycle != nil)
|
||||
retainCycle = nil
|
||||
}
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue