@ -6,22 +6,6 @@ import Foundation
import SignalServiceKit
import CloudKit
// f u n c F o r m a t A n a l y t i c s L o c a t i o n ( f i l e : S t r i n g , f u n c t i o n : S t r i n g ) - > N S S t r i n g {
// r e t u r n " \ ( ( f i l e a s N S S t r i n g ) . l a s t P a t h C o m p o n e n t ) : \ ( f u n c t i o n ) " a s N S S t r i n g
// }
//
// f u n c O W S P r o d E r r o r ( _ e v e n t N a m e : S t r i n g , f i l e : S t r i n g , f u n c t i o n : S t r i n g , l i n e : I n t 3 2 ) {
// l e t l o c a t i o n = F o r m a t A n a l y t i c s L o c a t i o n ( f i l e : f i l e , f u n c t i o n : f u n c t i o n )
// O W S A n a l y t i c s
// . l o g E v e n t ( e v e n t N a m e , s e v e r i t y : . e r r o r , p a r a m e t e r s : n i l , l o c a t i o n : l o c a t i o n . u t f 8 S t r i n g ! , l i n e : l i n e )
// }
//
// f u n c O W S P r o d I n f o ( _ e v e n t N a m e : S t r i n g , f i l e : S t r i n g , f u n c t i o n : S t r i n g , l i n e : I n t 3 2 ) {
// l e t l o c a t i o n = F o r m a t A n a l y t i c s L o c a t i o n ( f i l e : f i l e , f u n c t i o n : f u n c t i o n )
// O W S A n a l y t i c s
// . l o g E v e n t ( e v e n t N a m e , s e v e r i t y : . i n f o , p a r a m e t e r s : n i l , l o c a t i o n : l o c a t i o n . u t f 8 S t r i n g ! , l i n e : l i n e )
// }
@objc public class OWSBackupAPI : NSObject {
@objc
public class func recordIdForTest ( ) -> String {
@ -30,11 +14,15 @@ import CloudKit
@objc
public class func recordIdForAttachmentStream ( value : TSAttachmentStream ) -> String {
return " attachment-stream- \( value . uniqueId ) "
guard let uniqueId = value . uniqueId else {
owsFail ( " Database entity missing uniqueId. " )
return " unknown "
}
return " attachment-stream- \( uniqueId ) "
}
@objc
public class func saveTestFileToCloud ( fileUrl : NSURL ,
public class func saveTestFileToCloud ( fileUrl : URL,
completion : @ escaping ( Error ? ) -> Swift . Void ) {
saveFileToCloud ( fileUrl : fileUrl ,
recordId : recordIdForTest ( ) ,
@ -43,18 +31,22 @@ import CloudKit
}
@objc
public class func saveFileToCloud ( fileUrl : NS URL,
public class func saveFileToCloud ( fileUrl : URL,
recordId : String ,
recordType : String ,
completion : @ escaping ( Error ? ) -> Swift . Void ) {
let recordID = CKRecordID ( recordName : recordId )
let record = CKRecord ( recordType : recordType , recordID : recordID )
// a r t w o r k R e c o r d [ " t i t l e " ] = " M a c K e r r i c h e r S t a t e P a r k " a s N S S t r i n g
// a r t w o r k R e c o r d [ " a r t i s t " ] = " M e i C h e n " a s N S S t r i n g
// a r t w o r k R e c o r d [ " a d d r e s s " ] = " F o r t B r a g g , C A " a s N S S t r i n g
// a r t w o r k R e c o r d [ @ " t i t l e " ] = @ " M a c K e r r i c h e r S t a t e P a r k " ;
// a r t w o r k R e c o r d [ @ " a r t i s t " ] = @ " M e i C h e n " ;
// a r t w o r k R e c o r d [ @ " a d d r e s s " ] = @ " F o r t B r a g g , C A " ;
let asset = CKAsset ( fileURL : fileUrl )
record [ " payload " ] = asset
saveRecordToCloud ( record : record ,
completion : completion )
}
@objc
public class func saveRecordToCloud ( record : CKRecord ,
completion : @ escaping ( Error ? ) -> Swift . Void ) {
let myContainer = CKContainer . default ( )
let privateDatabase = myContainer . privateCloudDatabase
@ -77,7 +69,7 @@ import CloudKit
DispatchQueue . main . async {
switch accountStatus {
case . couldNotDetermine :
Logger . error ( " \( self . logTag ) could not determine CloudKit account status: \( error ) . " )
Logger . error ( " \( self . logTag ) could not determine CloudKit account status: \( String ( describing : 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 :
@ -89,7 +81,6 @@ import CloudKit
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 )
}
}