Upload test file to CloudKit.

This commit is contained in:
Matthew Chen 2018-03-06 10:29:25 -03:00
parent d06ad25d77
commit 593f7da72d
20 changed files with 1486 additions and 68 deletions

View File

@ -34,6 +34,10 @@
340FC8BB204DAC8D007AEB0F /* OWSAddToContactViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 340FC8A1204DAC8D007AEB0F /* OWSAddToContactViewController.m */; };
340FC8BC204DAC8D007AEB0F /* FingerprintViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 340FC8A2204DAC8D007AEB0F /* FingerprintViewController.m */; };
340FC8BD204DAC8D007AEB0F /* ShowGroupMembersViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 340FC8A6204DAC8D007AEB0F /* ShowGroupMembersViewController.m */; };
340FC8C0204DB7D2007AEB0F /* OWSBackupExport.m in Sources */ = {isa = PBXBuildFile; fileRef = 340FC8BF204DB7D2007AEB0F /* OWSBackupExport.m */; };
340FC8C2204DDF67007AEB0F /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 340FC8C1204DDF66007AEB0F /* CloudKit.framework */; };
340FC8C5204DE223007AEB0F /* DebugUIBackup.m in Sources */ = {isa = PBXBuildFile; fileRef = 340FC8C4204DE223007AEB0F /* DebugUIBackup.m */; };
340FC8C7204DE64D007AEB0F /* OWSBackupAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 340FC8C6204DE64D007AEB0F /* OWSBackupAPI.swift */; };
341F2C0F1F2B8AE700D07D6B /* DebugUIMisc.m in Sources */ = {isa = PBXBuildFile; fileRef = 341F2C0E1F2B8AE700D07D6B /* DebugUIMisc.m */; };
3430FE181F7751D4000EC51B /* GiphyAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3430FE171F7751D4000EC51B /* GiphyAPI.swift */; };
34330A5A1E7875FB00DF2FB9 /* fontawesome-webfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A591E7875FB00DF2FB9 /* fontawesome-webfont.ttf */; };
@ -567,6 +571,12 @@
340FC8A4204DAC8D007AEB0F /* AddToGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddToGroupViewController.h; sourceTree = "<group>"; };
340FC8A5204DAC8D007AEB0F /* FingerprintViewScanController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FingerprintViewScanController.h; sourceTree = "<group>"; };
340FC8A6204DAC8D007AEB0F /* ShowGroupMembersViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShowGroupMembersViewController.m; sourceTree = "<group>"; };
340FC8BE204DB7D1007AEB0F /* OWSBackupExport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSBackupExport.h; sourceTree = "<group>"; };
340FC8BF204DB7D2007AEB0F /* OWSBackupExport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSBackupExport.m; sourceTree = "<group>"; };
340FC8C1204DDF66007AEB0F /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; };
340FC8C3204DE223007AEB0F /* DebugUIBackup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIBackup.h; sourceTree = "<group>"; };
340FC8C4204DE223007AEB0F /* DebugUIBackup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUIBackup.m; sourceTree = "<group>"; };
340FC8C6204DE64D007AEB0F /* OWSBackupAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSBackupAPI.swift; sourceTree = "<group>"; };
341458471FBE11C4005ABCF9 /* fa */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fa; path = translations/fa.lproj/Localizable.strings; sourceTree = "<group>"; };
341F2C0D1F2B8AE700D07D6B /* DebugUIMisc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIMisc.h; sourceTree = "<group>"; };
341F2C0E1F2B8AE700D07D6B /* DebugUIMisc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUIMisc.m; sourceTree = "<group>"; };
@ -1118,6 +1128,7 @@
70377AAB1918450100CAF501 /* MobileCoreServices.framework in Frameworks */,
B9EB5ABD1884C002007CBB57 /* MessageUI.framework in Frameworks */,
453518991FC63DBF00210559 /* SignalMessaging.framework in Frameworks */,
340FC8C2204DDF67007AEB0F /* CloudKit.framework in Frameworks */,
76C87F19181EFCE600C4ACAB /* MediaPlayer.framework in Frameworks */,
768A1A2B17FC9CD300E00ED8 /* libz.dylib in Frameworks */,
A11CD70D17FA230600A2D1B1 /* QuartzCore.framework in Frameworks */,
@ -1624,11 +1635,14 @@
34D8C0221ED3673300188D7C /* DebugUI */ = {
isa = PBXGroup;
children = (
340FC8C3204DE223007AEB0F /* DebugUIBackup.h */,
340FC8C4204DE223007AEB0F /* DebugUIBackup.m */,
45638BDB1F3DD0D400128435 /* DebugUICalling.swift */,
34D8C0291ED3685800188D7C /* DebugUIContacts.h */,
34D8C02A1ED3685800188D7C /* DebugUIContacts.m */,
34E3EF0B1EFC235B007F6822 /* DebugUIDiskUsage.h */,
34E3EF0C1EFC235B007F6822 /* DebugUIDiskUsage.m */,
45B27B852037FFB400A539DF /* DebugUIFileBrowser.swift */,
34D8C0231ED3673300188D7C /* DebugUIMessages.h */,
34D8C0241ED3673300188D7C /* DebugUIMessages.m */,
341F2C0D1F2B8AE700D07D6B /* DebugUIMisc.h */,
@ -1645,7 +1659,6 @@
343A65941FC47D5E000477A1 /* DebugUISyncMessages.m */,
34D8C0251ED3673300188D7C /* DebugUITableViewController.h */,
34D8C0261ED3673300188D7C /* DebugUITableViewController.m */,
45B27B852037FFB400A539DF /* DebugUIFileBrowser.swift */,
);
path = DebugUI;
sourceTree = "<group>";
@ -1920,6 +1933,9 @@
34D99C911F2937CC00D284D6 /* OWSAnalytics.swift */,
34A9105E1FFEB113000C4745 /* OWSBackup.h */,
34A9105F1FFEB114000C4745 /* OWSBackup.m */,
340FC8C6204DE64D007AEB0F /* OWSBackupAPI.swift */,
340FC8BE204DB7D1007AEB0F /* OWSBackupExport.h */,
340FC8BF204DB7D2007AEB0F /* OWSBackupExport.m */,
4579431C1E7C8CE9008ED0C0 /* Pastelog.h */,
4579431D1E7C8CE9008ED0C0 /* Pastelog.m */,
450DF2041E0D74AC003D14BE /* Platform.swift */,
@ -2119,6 +2135,7 @@
D221A08C169C9E5E00537ABF /* Frameworks */ = {
isa = PBXGroup;
children = (
340FC8C1204DDF66007AEB0F /* CloudKit.framework */,
455A16DB1F1FEA0000F86704 /* Metal.framework */,
455A16DC1F1FEA0000F86704 /* MetalKit.framework */,
45847E861E4283C30080EAB3 /* Intents.framework */,
@ -3066,6 +3083,7 @@
450DF2091E0DD2C6003D14BE /* UserNotificationsAdaptee.swift in Sources */,
34D1F0821F8678AA0066283D /* ConversationHeaderView.m in Sources */,
34D1F0AB1F867BFC0066283D /* OWSContactOffersCell.m in Sources */,
340FC8C7204DE64D007AEB0F /* OWSBackupAPI.swift in Sources */,
343A65981FC4CFE7000477A1 /* ConversationScrollButton.m in Sources */,
34D1F0A91F867BFC0066283D /* ConversationViewCell.m in Sources */,
4505C2BF1E648EA300CEBF41 /* ExperienceUpgrade.swift in Sources */,
@ -3147,6 +3165,7 @@
45FBC5D11DF8592E00E9B410 /* SignalCall.swift in Sources */,
340FC8BB204DAC8D007AEB0F /* OWSAddToContactViewController.m in Sources */,
4523149E1F7E916B003A428C /* SlideOffAnimatedTransition.swift in Sources */,
340FC8C0204DB7D2007AEB0F /* OWSBackupExport.m in Sources */,
340FC8A7204DAC8D007AEB0F /* RegistrationViewController.m in Sources */,
452C468F1E427E200087B011 /* OutboundCallInitiator.swift in Sources */,
45F170BB1E2FC5D3003FC1F2 /* CallAudioService.swift in Sources */,
@ -3175,6 +3194,7 @@
4521C3C01F59F3BA00B4C582 /* TextFieldHelper.swift in Sources */,
34B3F87E1E8DF1700035BE1A /* InboxTableViewCell.m in Sources */,
340FC8AC204DAC8D007AEB0F /* PrivacySettingsTableViewController.m in Sources */,
340FC8C5204DE223007AEB0F /* DebugUIBackup.m in Sources */,
340FC8AE204DAC8D007AEB0F /* OWSSoundSettingsViewController.m in Sources */,
4579431E1E7C8CE9008ED0C0 /* Pastelog.m in Sources */,
34B3F8941E8DF1710035BE1A /* HomeViewController.m in Sources */,

View File

@ -12,12 +12,10 @@
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>iCloud.$(CFBundleIdentifier)</string>
<string>CloudKit</string>
</array>
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>
<key>com.apple.security.application-groups</key>
<array>
<string>group.org.whispersystems.signal.group</string>

View File

@ -92,7 +92,8 @@
[self updateTableContents];
dispatch_async(dispatch_get_main_queue(), ^{
[self showBackup];
// [self showBackup];
[self showDebugUI];
});
}

View File

@ -0,0 +1,13 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "DebugUIPage.h"
NS_ASSUME_NONNULL_BEGIN
@interface DebugUIBackup : DebugUIPage
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,76 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "DebugUIBackup.h"
#import "OWSBackup.h"
//#import "OWSCountryMetadata.h"
#import "OWSTableViewController.h"
//#import "RegistrationViewController.h"
#import "Signal-Swift.h"
//#import "ThreadUtil.h"
//#import <AxolotlKit/PreKeyBundle.h>
//#import <SignalMessaging/AttachmentSharing.h>
//#import <SignalMessaging/Environment.h>
//#import <SignalMessaging/UIImage+OWS.h>
//#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
//#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
//#import <SignalServiceKit/OWSPrimaryStorage+SessionStore.h>
//#import <SignalServiceKit/OWSVerificationStateChangeMessage.h>
//#import <SignalServiceKit/SecurityUtils.h>
//#import <SignalServiceKit/TSCall.h>
//#import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
//#import <SignalServiceKit/TSThread.h>
//#import <CloudKit/CloudKit.h>
#import <Curve25519Kit/Randomness.h>
@import CloudKit;
NS_ASSUME_NONNULL_BEGIN
@implementation DebugUIBackup
#pragma mark - Factory Methods
- (NSString *)name
{
return @"Backup";
}
- (nullable OWSTableSection *)sectionForThread:(nullable TSThread *)thread
{
NSMutableArray<OWSTableItem *> *items = [NSMutableArray new];
[items addObject:[OWSTableItem itemWithTitle:@"Backup test file @ CloudKit"
actionBlock:^{
[DebugUIBackup backupTestFile];
}]];
return [OWSTableSection sectionWithTitle:self.name items:items];
}
+ (void)backupTestFile
{
DDLogInfo(@"%@ backupTestFile.", self.logTag);
NSData *_Nullable data = [Randomness generateRandomBytes:32];
OWSAssert(data);
NSString *filePath = [OWSFileSystem temporaryFilePathWithFileExtension:@"pdf"];
BOOL success = [data writeToFile:filePath atomically:YES];
OWSAssert(success);
[OWSBackupAPI checkCloudKitAccessWithCompletion:^(BOOL hasAccess) {
if (hasAccess) {
[OWSBackupAPI saveTestFileToCloudWithFileUrl:[NSURL fileURLWithPath:filePath]
completion:^(NSError *_Nullable error){
// Do nothing, the API method will log for us.
}];
}
}];
}
@end
NS_ASSUME_NONNULL_END

View File

@ -693,12 +693,7 @@ NS_ASSUME_NONNULL_BEGIN
{
OWSAssert(size % 4 == 0);
NSMutableData *data = [NSMutableData dataWithCapacity:size];
for (size_t i = 0; i < size / 4; ++i) {
u_int32_t randomBits = arc4random();
[data appendBytes:(void *)&randomBits length:4];
}
return data;
return [Randomness generateRandomBytes:size];
}
+ (void)sendRandomAttachment:(TSThread *)thread uti:(NSString *)uti

View File

@ -1,13 +1,11 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "DebugUIPage.h"
NS_ASSUME_NONNULL_BEGIN
@class TSThread;
@interface DebugUIMisc : DebugUIPage
@end

View File

@ -3,6 +3,7 @@
//
#import "DebugUITableViewController.h"
#import "DebugUIBackup.h"
#import "DebugUIContacts.h"
#import "DebugUIDiskUsage.h"
#import "DebugUIMessages.h"
@ -110,6 +111,8 @@ NS_ASSUME_NONNULL_BEGIN
}];
[subsectionItems addObject:documentsFileBrowserItem];
[subsectionItems addObject:[self itemForSubsection:[DebugUIMisc new] viewController:viewController thread:thread]];
[subsectionItems
addObject:[self itemForSubsection:[DebugUIBackup new] viewController:viewController thread:thread]];
[contents addSection:[OWSTableSection sectionWithTitle:@"Sections" items:subsectionItems]];
@ -135,6 +138,7 @@ NS_ASSUME_NONNULL_BEGIN
[subsectionItems
addObject:[self itemForSubsection:[DebugUISyncMessages new] viewController:viewController thread:nil]];
[subsectionItems addObject:[self itemForSubsection:[DebugUIMisc new] viewController:viewController thread:nil]];
[subsectionItems addObject:[self itemForSubsection:[DebugUIBackup new] viewController:viewController thread:nil]];
[contents addSection:[OWSTableSection sectionWithTitle:@"Sections" items:subsectionItems]];
viewController.contents = contents;

View File

@ -188,7 +188,7 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
bottomBanner.autoPinEdge(toSuperviewEdge: .top)
bottomBanner.autoPinWidthToSuperview()
self.autoPinView(toBottomGuideOrKeyboard:bottomBanner)
self.autoPinView(toBottomGuideOrKeyboard: bottomBanner)
// The Giphy API requires us to "show their trademark prominently" in our GIF experience.
let logoImage = UIImage(named: "giphy_logo")
@ -454,9 +454,7 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
progressiveSearchTimer = nil
guard let text = searchBar.text else {
OWSAlerts.showAlert(title: NSLocalizedString("ALERT_ERROR_TITLE",
comment: ""),
message: NSLocalizedString("GIF_PICKER_VIEW_MISSING_QUERY",
OWSAlerts.showErrorAlert(withMessage: NSLocalizedString("GIF_PICKER_VIEW_MISSING_QUERY",
comment: "Alert message shown when user tries to search for GIFs without entering any search terms."))
return
}

View File

@ -728,8 +728,7 @@ NS_ASSUME_NONNULL_BEGIN
if ([MFMessageComposeViewController canSendText]) {
[inviteFlow sendSMSToPhoneNumbers:@[ phoneNumber ]];
} else {
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")
message:NSLocalizedString(@"UNSUPPORTED_FEATURE_ERROR", @"")];
[OWSAlerts showErrorAlertWithMessage:NSLocalizedString(@"UNSUPPORTED_FEATURE_ERROR", @"")];
}
}];

View File

@ -322,10 +322,9 @@ NS_ASSUME_NONNULL_BEGIN
// Clear the PIN so that the user can try again.
self.pinTextfield.text = nil;
[OWSAlerts
showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")
message:NSLocalizedString(@"ENABLE_2FA_VIEW_PIN_DOES_NOT_MATCH",
@"Error indicating that the entered 'two-factor auth PINs' do not match.")];
[OWSAlerts showErrorAlertWithMessage:
NSLocalizedString(@"ENABLE_2FA_VIEW_PIN_DOES_NOT_MATCH",
@"Error indicating that the entered 'two-factor auth PINs' do not match.")];
}
break;
}
@ -370,11 +369,10 @@ NS_ASSUME_NONNULL_BEGIN
[modalActivityIndicator dismissWithCompletion:^{
[weakSelf updateTableContents];
[OWSAlerts
showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")
message:NSLocalizedString(@"ENABLE_2FA_VIEW_COULD_NOT_DISABLE_2FA",
@"Error indicating that attempt to disable 'two-factor "
@"auth' failed.")];
[OWSAlerts showErrorAlertWithMessage:
NSLocalizedString(@"ENABLE_2FA_VIEW_COULD_NOT_DISABLE_2FA",
@"Error indicating that attempt to disable 'two-factor "
@"auth' failed.")];
}];
}];
}];
@ -407,11 +405,10 @@ NS_ASSUME_NONNULL_BEGIN
[weakSelf updateTableContents];
[OWSAlerts
showAlertWithTitle:NSLocalizedString(@"ENABLE_2FA_VIEW_COULD_NOT_ENABLE_2FA",
@"Error indicating that attempt to enable 'two-factor "
@"auth' failed.")
message:error.localizedDescription];
[OWSAlerts showErrorAlertWithMessage:
NSLocalizedString(@"ENABLE_2FA_VIEW_COULD_NOT_ENABLE_2FA",
@"Error indicating that attempt to enable 'two-factor "
@"auth' failed.")];
}];
}];
}];

View File

@ -367,8 +367,8 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
NSString *normalizedProfileName = [self normalizedProfileName];
if ([OWSProfileManager.sharedManager isProfileNameTooLong:normalizedProfileName]) {
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")
message:NSLocalizedString(@"PROFILE_VIEW_ERROR_PROFILE_NAME_TOO_LONG",
[OWSAlerts
showErrorAlertWithMessage:NSLocalizedString(@"PROFILE_VIEW_ERROR_PROFILE_NAME_TOO_LONG",
@"Error message shown when user tries to update profile with a profile name "
@"that is too long.")];
return;
@ -396,14 +396,11 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
[alertController
dismissViewControllerAnimated:NO
completion:^{
[OWSAlerts
showAlertWithTitle:NSLocalizedString(
@"ALERT_ERROR_TITLE", @"")
message:
NSLocalizedString(
@"PROFILE_VIEW_ERROR_UPDATE_FAILED",
@"Error message shown when a "
@"profile update fails.")];
[OWSAlerts showErrorAlertWithMessage:
NSLocalizedString(
@"PROFILE_VIEW_ERROR_UPDATE_FAILED",
@"Error message shown when a "
@"profile update fails.")];
}];
}];
}];

View File

@ -6,10 +6,10 @@
//#import "NSUserDefaults+OWS.h"
//#import "Signal-Swift.h"
#import "zlib.h"
//#import "zlib.h"
//#import <SAMKeychain/SAMKeychain.h>
#import <SSZipArchive/SSZipArchive.h>
//#import <SSZipArchive/SSZipArchive.h>
//#import <SignalMessaging/SignalMessaging-Swift.h>
//#import <SignalServiceKit/Cryptography.h>
@ -17,7 +17,10 @@
//#import <SignalServiceKit/OWSPrimaryStorage.h>
#import "NSNotificationCenter+OWS.h"
#import "OWSBackupExport.h"
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/OWSBackupStorage.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/YapDatabaseConnection+OWS.h>
NSString *const NSNotificationNameBackupStateDidChange = @"NSNotificationNameBackupStateDidChange";
@ -50,15 +53,10 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
//- (NSData *)databasePassword;
//
//+ (void)storeDatabasePassword:(NSString *)password;
// This property should only be accessed on the main thread.
@property (nonatomic, nullable) OWSBackupExport *backupExport;
@end
#pragma mark -
@interface OWSBackup () <SSZipArchiveDelegate>
//<SSZipArchiveDelegate>
//@property (nonatomic) OWSBackupState backupState;
//
@ -114,6 +112,15 @@ NS_ASSUME_NONNULL_BEGIN
OWSSingletonAssert();
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:OWSApplicationDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(registrationStateDidChange)
name:RegistrationStateDidChangeNotification
object:nil];
return self;
}
@ -124,10 +131,6 @@ NS_ASSUME_NONNULL_BEGIN
//- (void)observeNotifications
//{
// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(applicationDidBecomeActive:)
// name:OWSApplicationDidBecomeActiveNotification
// object:nil];
//}
//- (void)dealloc
@ -167,6 +170,56 @@ NS_ASSUME_NONNULL_BEGIN
userInfo:nil];
}
- (BOOL)shouldHaveBackupExport
{
if (!self.isBackupEnabled) {
return NO;
}
if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) {
// Only start backups when app is in the background.
return NO;
}
if (![TSAccountManager isRegistered]) {
return NO;
}
// TODO: There's probably other conditions that affect this decision.
return YES;
}
- (void)ensureBackupExportState
{
OWSAssertIsOnMainThread();
if (!self.shouldHaveBackupExport && self.backupExport) {
[self.backupExport cancel];
self.backupExport = nil;
} else if (self.shouldHaveBackupExport && !self.backupExport) {
self.backupExport =
[[OWSBackupExport alloc] initWithDelegate:self primaryStorage:[OWSPrimaryStorage sharedManager]];
[self.backupExport start];
}
// BOOL shouldHaveBackupExport
// OWSBackupExport *backupExport
}
#pragma mark -
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
OWSAssertIsOnMainThread();
[self ensureBackupExportState];
}
- (void)registrationStateDidChange
{
OWSAssertIsOnMainThread();
[self ensureBackupExportState];
}
//- (void)setBackupProgress:(CGFloat)backupProgress
//{
// _backupProgress = backupProgress;

View File

@ -0,0 +1,98 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
import SignalServiceKit
import CloudKit
//func FormatAnalyticsLocation(file: String, function: String) -> NSString {
// return "\((file as NSString).lastPathComponent):\(function)" as NSString
//}
//
//func OWSProdError(_ eventName: String, file: String, function: String, line: Int32) {
// let location = FormatAnalyticsLocation(file: file, function: function)
// OWSAnalytics
// .logEvent(eventName, severity: .error, parameters: nil, location: location.utf8String!, line:line)
//}
//
//func OWSProdInfo(_ eventName: String, file: String, function: String, line: Int32) {
// let location = FormatAnalyticsLocation(file: file, function: function)
// OWSAnalytics
// .logEvent(eventName, severity: .info, parameters: nil, location: location.utf8String!, line:line)
//}
@objc public class OWSBackupAPI: NSObject {
@objc
public class func recordIdForTest() -> String {
return "test-\(NSUUID().uuidString)"
}
@objc
public class func recordIdForAttachmentStream(value: TSAttachmentStream) -> String {
return "attachment-stream-\(value.uniqueId)"
}
@objc
public class func saveTestFileToCloud(fileUrl: NSURL,
completion: @escaping (Error?) -> Swift.Void) {
saveFileToCloud(fileUrl: fileUrl,
recordId: recordIdForTest(),
recordType: "test",
completion: completion)
}
@objc
public class func saveFileToCloud(fileUrl: NSURL,
recordId: String,
recordType: String,
completion: @escaping (Error?) -> Swift.Void) {
let recordID = CKRecordID(recordName: recordId)
let record = CKRecord(recordType: recordType, recordID: recordID)
// artworkRecord["title"] = "MacKerricher State Park" as NSString
// artworkRecord["artist"] = "Mei Chen" as NSString
// artworkRecord["address"] = "Fort Bragg, CA" as NSString
// artworkRecord[@"title" ] = @"MacKerricher State Park";
// artworkRecord[@"artist"] = @"Mei Chen";
// artworkRecord[@"address"] = @"Fort Bragg, CA";
let myContainer = CKContainer.default()
let privateDatabase = myContainer.privateCloudDatabase
privateDatabase.save(record) {
(record, error) in
if let error = error {
Logger.error("\(self.logTag) error saving record: \(error)")
completion(error)
} else {
Logger.info("\(self.logTag) saved record.")
completion(nil)
}
}
}
@objc
public class func checkCloudKitAccess(completion: @escaping (Bool) -> Swift.Void) {
CKContainer.default().accountStatus(completionHandler: { (accountStatus, error) in
DispatchQueue.main.async {
switch accountStatus {
case .couldNotDetermine:
Logger.error("\(self.logTag) could not determine CloudKit account status:\(error).")
OWSAlerts.showErrorAlert(withMessage: NSLocalizedString("CLOUDKIT_STATUS_COULD_NOT_DETERMINE", comment: "Error indicating that the app could not determine that user's CloudKit account status"))
completion(false)
case .noAccount:
Logger.error("\(self.logTag) no CloudKit account.")
OWSAlerts.showErrorAlert(withMessage: NSLocalizedString("CLOUDKIT_STATUS_NO_ACCOUNT", comment: "Error indicating that user does not have an iCloud account."))
completion(false)
case .restricted:
Logger.error("\(self.logTag) restricted CloudKit account.")
OWSAlerts.showErrorAlert(withMessage: NSLocalizedString("CLOUDKIT_STATUS_RESTRICTED", comment: "Error indicating that the app was prevented from accessing the user's CloudKit account."))
completion(false)
case .available:
Logger.error("\(self.logTag) no CloudKit account.")
completion(true)
}
}
})
}
}

View File

@ -0,0 +1,70 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
// extern NSString *const OWSBackup_FileExtension;
// extern NSString *const NSNotificationNameBackupStateDidChange;
@protocol OWSBackupExportDelegate <NSObject>
- (void)backupExportDidSucceed;
- (void)backupExportDidFailWithError:(NSError *)error;
@end
//#pragma mark -
// typedef NS_ENUM(NSUInteger, OWSBackupState) {
// OWSBackupState_AtRest = 0,
// OWSBackupState_InProgress,
// // OWSBackupState_Cancelled,
// OWSBackupState_Failed,
//};
@class OWSPrimaryStorage;
@interface OWSBackupExport : NSObject
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithDelegate:(id<OWSBackupExportDelegate>)delegate
primaryStorage:(OWSPrimaryStorage *)primaryStorage;
- (void)start;
- (void)cancel;
//@property (nonatomic, readonly) OWSBackupState backupExportState;
//
////@property (nonatomic, readonly) CGFloat backupProgress;
////
////// If non-nil, backup is encrypted.
////@property (nonatomic, nullable, readonly) NSString *backupPassword;
////
////// Only applies to "backup export" task.
////@property (nonatomic, nullable, readonly) TSThread *currentThread;
////
////@property (nonatomic, readonly) NSString *backupZipPath;
////
//
//
//+ (instancetype)sharedManager;
//
//- (BOOL)isBackupEnabled;
//- (void)setIsBackupEnabled:(BOOL)value;
//- (void)exportBackup:(nullable TSThread *)currentThread skipPassword:(BOOL)skipPassword;
//
//- (void)importBackup:(NSString *)backupZipPath password:(NSString *_Nullable)password;
//
//- (void)cancel;
//
//+ (void)applicationDidFinishLaunching;
@end
NS_ASSUME_NONNULL_END

File diff suppressed because it is too large Load Diff

View File

@ -338,10 +338,8 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
[modalActivityIndicator
dismissViewControllerAnimated:NO
completion:^{
[OWSAlerts showAlertWithTitle:
NSLocalizedString(@"ALERT_ERROR_TITLE",
@"Title for a generic error alert.")
message:error.localizedDescription];
[OWSAlerts
showErrorAlertWithMessage:error.localizedDescription];
}];
}];
}];

View File

@ -132,8 +132,8 @@ NS_ASSUME_NONNULL_BEGIN
if ([error.domain isEqualToString:NSOSStatusErrorDomain]
&& (error.code == kAudioFileInvalidFileError || error.code == kAudioFileStreamError_InvalidFile)) {
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")
message:NSLocalizedString(@"INVALID_AUDIO_FILE_ALERT_ERROR_MESSAGE",
[OWSAlerts
showErrorAlertWithMessage:NSLocalizedString(@"INVALID_AUDIO_FILE_ALERT_ERROR_MESSAGE",
@"Message for the alert indicating that an audio file is invalid.")];
}

View File

@ -12,11 +12,13 @@ import Foundation
@objc
static public let dismissButton = NSLocalizedString("DISMISS_BUTTON_TEXT", comment: "Short text to dismiss current modal / actionsheet / screen")
@objc
static public let cancelButton = NSLocalizedString("TXT_CANCEL_TITLE", comment:"Label for the cancel button in an alert or action sheet.")
static public let cancelButton = NSLocalizedString("TXT_CANCEL_TITLE", comment: "Label for the cancel button in an alert or action sheet.")
@objc
static public let retryButton = NSLocalizedString("RETRY_BUTTON_TEXT", comment:"Generic text for button that retries whatever the last action was.")
static public let retryButton = NSLocalizedString("RETRY_BUTTON_TEXT", comment: "Generic text for button that retries whatever the last action was.")
@objc
static public let openSettingsButton = NSLocalizedString("OPEN_SETTINGS_BUTTON", comment: "Button text which opens the settings app")
@objc
static public let errorAlertTitle = NSLocalizedString("ALERT_ERROR_TITLE", comment: "")
}
@objc public class MessageStrings: NSObject {

View File

@ -54,6 +54,11 @@ import Foundation
CurrentAppContext().frontmostViewController()?.present(alert, animated: true, completion: nil)
}
@objc
public class func showErrorAlert(withMessage message: String) {
self.showAlert(withTitle: CommonStrings.errorAlertTitle, message: message, buttonTitle: nil)
}
@objc
public class var cancelAction: UIAlertAction {
let action = UIAlertAction(title: CommonStrings.cancelButton, style: .cancel) { _ in