marinofaggiana 4 years ago
parent
commit
9591eb07ab

+ 0 - 92
Carthage/Checkouts/CocoaLumberjack/.travis.yml

@@ -1,92 +0,0 @@
-
-language: objective-c
-osx_image: xcode11
-
-branches:
-    only:
-        - master
-
-env:
-  global:
-    - LC_CTYPE=en_US.UTF-8
-    - LANG=en_US.UTF-8
-
-
-before_install:
-    - env
-    - locale
-    - gem install cocoapods --prerelease --no-document --quiet
-    - gem install xcpretty --no-document --quiet
-    - pod --version
-    - xcpretty --version
-    - xcodebuild -version
-    - xcodebuild -showsdks
-
-script:
-    - set -o pipefail
-
-    - echo "Check external deployment platforms"
-    - echo "Check CocoaPods CocoaLumberjack.podspec"
-    - pod lib lint
-
-    - echo "Check Swift Package manager Package.swift"
-    - swift test
-
-    - echo "Build as static library"
-    - xcodebuild clean build -workspace Xcode/Lumberjack.xcworkspace -scheme 'CocoaLumberjack-Static' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Release | xcpretty -c
-    - xcodebuild clean build -workspace Xcode/Lumberjack.xcworkspace -scheme 'CocoaLumberjack-Static' -sdk macosx -configuration Release | xcpretty -c
-
-    - echo "Build as dynamic framework (ObjectiveC), each platform (iOS, macOS, tvOS, watchOS)"
-    - xcodebuild clean build -workspace Xcode/Lumberjack.xcworkspace -scheme 'CocoaLumberjack' -configuration Release -sdk iphonesimulator | xcpretty -c
-    - xcodebuild clean build -workspace Xcode/Lumberjack.xcworkspace -scheme 'CocoaLumberjack' -configuration Release -sdk macosx | xcpretty -c
-    - xcodebuild clean build -workspace Xcode/Lumberjack.xcworkspace -scheme 'CocoaLumberjack' -destination 'platform=tvOS Simulator,name=Apple TV 4K' -configuration Release -sdk appletvsimulator | xcpretty -c
-    - xcodebuild clean build -workspace Xcode/Lumberjack.xcworkspace -scheme 'CocoaLumberjack' -configuration Release -sdk watchsimulator | xcpretty -c
-
-    - echo "Build as dynamic framework (Swift), each platform (iOS, macOS, tvOS, watchOS)"
-    - xcodebuild clean build -workspace Xcode/Lumberjack.xcworkspace -scheme 'CocoaLumberjackSwift' -configuration Release -sdk iphonesimulator | xcpretty -c
-    - xcodebuild clean build -workspace Xcode/Lumberjack.xcworkspace -scheme 'CocoaLumberjackSwift' -configuration Release -sdk macosx | xcpretty -c
-    - xcodebuild clean build -workspace Xcode/Lumberjack.xcworkspace -scheme 'CocoaLumberjackSwift' -destination 'platform=tvOS Simulator,name=Apple TV 4K' -configuration Release -sdk appletvsimulator | xcpretty -c
-    - xcodebuild clean build -workspace Xcode/Lumberjack.xcworkspace -scheme 'CocoaLumberjackSwift' -configuration Release -sdk watchsimulator | xcpretty -c
-
-    - echo "Build test app using the static library"
-    - xcodebuild clean build -project Integration/Integration.xcodeproj -scheme 'iOSStaticLibraryIntegration' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Release | xcpretty -c
-
-    - echo "Build test apps using the dynamic framework, each platform (iOS, macOS, tvOS, watchOS)"
-    - xcodebuild clean build -project Integration/Integration.xcodeproj -scheme 'macOSSwiftIntegration' -configuration Release -sdk macosx | xcpretty -c
-    - xcodebuild clean build -project Integration/Integration.xcodeproj -scheme 'iOSFrameworkIntegration' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Release | xcpretty -c
-    - xcodebuild clean build -project Integration/Integration.xcodeproj -scheme 'tvOSSwiftIntegration' -destination 'platform=tvOS Simulator,name=Apple TV 4K' -configuration Release -sdk appletvsimulator | xcpretty -c
-    - xcodebuild clean build -project Integration/Integration.xcodeproj -scheme 'watchOSSwiftIntegration' -configuration Release -sdk watchsimulator -destination 'platform=iOS Simulator,name=iPhone 11 Pro' | xcpretty -c
-
-    - echo "Run the tests"
-    - xcodebuild test -skip-testing:'iOS Tests/DDFileLoggerPerformanceTests' -project Tests/Tests.xcodeproj -scheme 'iOS Tests' -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 11 Pro,OS=latest' GCC_GENERATE_TEST_COVERAGE_FILES=YES | xcpretty -c
-    - xcodebuild test -skip-testing:'OS X Tests/DDFileLoggerPerformanceTests' -project Tests/Tests.xcodeproj -scheme 'OS X Tests' -sdk macosx GCC_GENERATE_TEST_COVERAGE_FILES=YES | xcpretty -c
-
-    - echo "Building the Demos"
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'BenchmarkIPhone' -configuration Release -sdk iphonesimulator | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'BenchmarkMac' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'CLI' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'CaptureASL' -configuration Release -sdk iphonesimulator | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'ContextFilter' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'CoreDataLogger' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'CustomFormatters' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'CustomLogLevels' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'DispatchQueueLogger' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'FineGrainedLogging' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'GlobalLogLevel' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'LogFileCompressor' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'NonArcTest' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'OverflowTestMac' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'PerUserLogLevels' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'RegisteredLoggingTest (Desktop)' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'RegisteredLoggingTest (Mobile)' -configuration Release -sdk iphonesimulator | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'RollingTestMac' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'SQLiteLogger' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'TestXcodeColors (Desktop)' | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'TextXcodeColors (Mobile)' -configuration Release -sdk iphonesimulator | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'UniversalApp' -configuration Release -sdk iphonesimulator | xcpretty -c
-    - xcodebuild clean build -workspace Demos/Demos.xcworkspace -scheme 'WebServerIPhone' -configuration Release -sdk iphonesimulator | xcpretty -c
-
-    - bundle exec danger
-
-after_success:
-    - bash <(curl -s https://codecov.io/bash)

+ 1 - 29
iOSClient/AutoUpload/NCAutoUpload.m

@@ -433,7 +433,7 @@
                 
                 dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
                 
-                [self extractLivePhotoAsset:asset filePath:filePath withCompletion:^(NSURL *url) {
+                [CCUtility extractLivePhotoAsset:asset filePath:filePath withCompletion:^(NSURL *url) {
                     if (url != nil) {
                         unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:url.path error:nil] fileSize];
                         
@@ -567,34 +567,6 @@
     return nil;
 }
 
-- (void)extractLivePhotoAsset:(PHAsset*)asset filePath:(NSString *)filePath withCompletion:(void (^)(NSURL* url))completion {
-    
-    [CCUtility removeFileAtPath:filePath];
-    NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
-    PHLivePhotoRequestOptions *options = [PHLivePhotoRequestOptions new];
-    options.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat;
-    options.networkAccessAllowed = YES;
-    
-    [[PHImageManager defaultManager] requestLivePhotoForAsset:asset targetSize:[UIScreen mainScreen].bounds.size contentMode:PHImageContentModeDefault options:options resultHandler:^(PHLivePhoto * _Nullable livePhoto, NSDictionary * _Nullable info) {
-        if (livePhoto) {
-            NSArray *assetResources = [PHAssetResource assetResourcesForLivePhoto:livePhoto];
-            PHAssetResource *videoResource = nil;
-            for(PHAssetResource *resource in assetResources){
-                if (resource.type == PHAssetResourceTypePairedVideo) {
-                    videoResource = resource;
-                    break;
-                }
-            }
-            if(videoResource){
-                [[PHAssetResourceManager defaultManager] writeDataForAssetResource:videoResource toFile:fileUrl options:nil completionHandler:^(NSError * _Nullable error) {
-                    if (!error) {
-                        completion(fileUrl);
-                    } else { completion(nil); }
-                }];
-            } else { completion(nil); }
-        } else { completion(nil); }
-    }];
-}
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Align Photo Library ====
 #pragma --------------------------------------------------------------------------------------------

+ 1 - 1
iOSClient/Main/CCMain.h

@@ -72,7 +72,7 @@
 - (void)readFolder:(NSString *)serverUrl;
 - (void)readFileReloadFolder;
 
-- (void)uploadFileAsset:(NSMutableArray *)assets urls:(NSMutableArray *)urls serverUrl:(NSString *)serverUrl useSubFolder:(BOOL)useSubFolder session:(NSString *)session;
+- (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl useSubFolder:(BOOL)useSubFolder session:(NSString *)session;
 
 - (void)openAssetsPickerController;
 - (void)openImportDocumentPicker;

+ 51 - 38
iOSClient/Main/CCMain.m

@@ -831,12 +831,12 @@
 {
     NCPhotosPickerViewController *viewController = [[NCPhotosPickerViewController alloc] init:self maxSelectedAssets:100 singleSelectedMode:false];
     
-    [viewController openPhotosPickerViewControllerWithPhAssets:^(NSArray<PHAsset *> * _Nullable assets, NSArray<NSURL *> * urls) {
+    [viewController openPhotosPickerViewControllerWithPhAssets:^(NSArray<PHAsset *> * _Nullable assets) {
         if (assets.count > 0) {
             dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
                 NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
                 
-                NCCreateFormUploadAssets *form = [[NCCreateFormUploadAssets alloc] initWithServerUrl:serverUrl assets:(NSMutableArray *)assets urls:(NSMutableArray *)urls cryptated:NO session:NCCommunicationCommon.shared.sessionIdentifierBackground delegate:self];
+                NCCreateFormUploadAssets *form = [[NCCreateFormUploadAssets alloc] initWithServerUrl:serverUrl assets:(NSMutableArray *)assets cryptated:NO session:NCCommunicationCommon.shared.sessionIdentifierBackground delegate:self];
                 
                 UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:form];
                 [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
@@ -978,7 +978,7 @@
 #pragma mark ===== Upload new Photos/Videos =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)uploadFileAsset:(NSMutableArray *)assets urls:(NSMutableArray *)urls serverUrl:(NSString *)serverUrl useSubFolder:(BOOL)useSubFolder session:(NSString *)session
+- (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl useSubFolder:(BOOL)useSubFolder session:(NSString *)session
 {
     NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:appDelegate.activeUrl];
 
@@ -990,10 +990,12 @@
         }
     }
     
-    [self uploadFileAsset:assets urls:urls serverUrl:serverUrl autoUploadPath:autoUploadPath useSubFolder:useSubFolder session:session];
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        [self uploadFileAsset:assets serverUrl:serverUrl autoUploadPath:autoUploadPath useSubFolder:useSubFolder session:session];
+    });
 }
 
-- (void)uploadFileAsset:(NSArray *)assets urls:(NSArray *)urls serverUrl:(NSString *)serverUrl autoUploadPath:(NSString *)autoUploadPath useSubFolder:(BOOL)useSubFolder session:(NSString *)session
+- (void)uploadFileAsset:(NSArray *)assets serverUrl:(NSString *)serverUrl autoUploadPath:(NSString *)autoUploadPath useSubFolder:(BOOL)useSubFolder session:(NSString *)session
 {
     NSMutableArray *metadatasNOConflict = [NSMutableArray new];
     NSMutableArray *metadatasMOV = [NSMutableArray new];
@@ -1039,46 +1041,57 @@
         }
         
         // Add Medtadata MOV LIVE PHOTO for upload
-        if ((asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive || asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive+PHAssetMediaSubtypePhotoHDR) && CCUtility.getLivePhoto && urls.count == assets.count) {
+        if ((asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive || asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive+PHAssetMediaSubtypePhotoHDR) && CCUtility.getLivePhoto) {
                 
-            NSUInteger index = [assets indexOfObject:asset];
-            NSURL *url = [urls objectAtIndex:index];
-            NSString *fileNameNoExt = [fileName stringByDeletingPathExtension];
-            NSString *fileName = [NSString stringWithFormat:@"%@.mov", fileNameNoExt];
-            unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:url.path error:nil] fileSize];
+            NSString *fileNameMove = [NSString stringWithFormat:@"%@.mov", fileName.stringByDeletingPathExtension];
+            NSString *ocId = [[NSUUID UUID] UUIDString];
+            NSString *filePath = [CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileNameMove];
 
-            tableMetadata *metadataMOVForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileName ocId:[[NSUUID UUID] UUIDString] serverUrl:serverUrl urlBase:appDelegate.activeUrl url:@"" contentType:@""];
+            dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
             
-            metadataMOVForUpload.session = session;
-            metadataMOVForUpload.sessionSelector = selectorUploadFile;
-            metadataMOVForUpload.size = fileSize;
-            metadataMOVForUpload.status = k_metadataStatusWaitUpload;
-            
-            // Prepare file and directory
-            [CCUtility copyFileAtPath:url.path toPath:[CCUtility getDirectoryProviderStorageOcId:metadataMOVForUpload.ocId fileNameView:fileName]];
+            [CCUtility extractLivePhotoAsset:asset filePath:filePath withCompletion:^(NSURL *url) {
+                if (url != nil) {
+                    unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:url.path error:nil] fileSize];
+                    
+                    tableMetadata *metadataMOVForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileNameMove ocId:ocId serverUrl:serverUrl urlBase:appDelegate.activeUrl url:@"" contentType:@""];
+                    
+                    metadataMOVForUpload.session = session;
+                    metadataMOVForUpload.sessionSelector = selectorUploadFile;
+                    metadataMOVForUpload.size = fileSize;
+                    metadataMOVForUpload.status = k_metadataStatusWaitUpload;
+                    metadataMOVForUpload.typeFile = k_metadataTypeFile_video;
+
+                    [metadatasMOV addObject:metadataMOVForUpload];
+                }
+                
+                dispatch_semaphore_signal(semaphore);
+            }];
             
-            [metadatasMOV addObject:metadataMOVForUpload];
+            while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
+                   [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:30]];
         }
     }
     
-    // Verify if file(s) exists
-    if (metadatasUploadInConflict.count > 0) {
-        
-        NCCreateFormUploadConflict *conflict = [[UIStoryboard storyboardWithName:@"NCCreateFormUploadConflict" bundle:nil] instantiateInitialViewController];
-        conflict.serverUrl = self.serverUrl;
-        conflict.metadatasNOConflict = metadatasNOConflict;
-        conflict.metadatasMOV = metadatasMOV;
-        conflict.metadatasUploadInConflict = metadatasUploadInConflict;
-        
-        [self presentViewController:conflict animated:YES completion:nil];
-        
-    } else {
-        
-        [[NCManageDatabase sharedInstance] addMetadatas:metadatasNOConflict];
-        [[NCManageDatabase sharedInstance] addMetadatas:metadatasMOV];
-        
-        [[appDelegate networkingAutoUpload] startProcess];
-    }
+    dispatch_async(dispatch_get_main_queue(), ^{
+        // Verify if file(s) exists
+        if (metadatasUploadInConflict.count > 0) {
+            
+            NCCreateFormUploadConflict *conflict = [[UIStoryboard storyboardWithName:@"NCCreateFormUploadConflict" bundle:nil] instantiateInitialViewController];
+            conflict.serverUrl = self.serverUrl;
+            conflict.metadatasNOConflict = metadatasNOConflict;
+            conflict.metadatasMOV = metadatasMOV;
+            conflict.metadatasUploadInConflict = metadatasUploadInConflict;
+            
+            [self presentViewController:conflict animated:YES completion:nil];
+            
+        } else {
+            
+            [[NCManageDatabase sharedInstance] addMetadatas:metadatasNOConflict];
+            [[NCManageDatabase sharedInstance] addMetadatas:metadatasMOV];
+            
+            [[appDelegate networkingAutoUpload] startProcess];
+        }
+    });
 }
 
 

+ 2 - 4
iOSClient/Main/Create cloud/NCCreateFormUploadAssets.swift

@@ -33,7 +33,6 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
     var serverUrl: String = ""
     var titleServerUrl: String?
     var assets = NSMutableArray()
-    var urls = NSMutableArray()
     var cryptated: Bool = false
     var session: String = ""
     weak var delegate: createFormUploadAssetsDelegate?
@@ -42,7 +41,7 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
     let targetSizeImagePreview = CGSize(width:100, height: 100)
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     
-    @objc convenience init(serverUrl : String, assets : NSMutableArray, urls: NSMutableArray, cryptated : Bool, session : String, delegate: createFormUploadAssetsDelegate) {
+    @objc convenience init(serverUrl : String, assets : NSMutableArray, cryptated : Bool, session : String, delegate: createFormUploadAssetsDelegate) {
         
         self.init()
         
@@ -58,7 +57,6 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
         
         self.serverUrl = serverUrl
         self.assets = assets
-        self.urls = urls
         self.cryptated = cryptated
         self.session = session
         self.delegate = delegate
@@ -339,7 +337,7 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
                 useSubFolder = (useSubFolderRow.value! as AnyObject).boolValue
             }
             
-            self.appDelegate.activeMain.uploadFileAsset(self.assets, urls: self.urls, serverUrl: self.serverUrl, useSubFolder: useSubFolder, session: self.session)
+            self.appDelegate.activeMain.uploadFileAsset(self.assets, serverUrl: self.serverUrl, useSubFolder: useSubFolder, session: self.session)
         })
     }
     

+ 15 - 2
iOSClient/Main/NCPhotosPickerViewController.swift

@@ -37,10 +37,9 @@ class NCPhotosPickerViewController: NSObject {
         self.singleSelectedMode = singleSelectedMode
     }
     
-    @objc func openPhotosPickerViewController(phAssets: @escaping ([PHAsset]?, [URL]?) -> ()) {
+    @objc func openPhotosPickerViewController(phAssets: @escaping ([PHAsset]?) -> ()) {
         
         var selectedPhAssets: [PHAsset] = []
-        var selectedUrls: [URL] = []
         var configure = TLPhotosPickerConfigure()
         
         configure.cancelTitle = NSLocalizedString("_cancel_", comment: "")
@@ -52,6 +51,19 @@ class NCPhotosPickerViewController: NSObject {
         configure.selectedColor = NCBrandColor.sharedInstance.brandElement
         configure.singleSelectedMode = singleSelectedMode
         
+        let viewController = customPhotoPickerViewController(withTLPHAssets: { (assets) in
+            
+            for asset: TLPHAsset in assets {
+                if asset.phAsset != nil {
+                    selectedPhAssets.append(asset.phAsset!)
+                }
+            }
+            
+            phAssets(selectedPhAssets)
+            
+        }, didCancel: nil)
+        
+        /*
         let viewController = customPhotoPickerViewController(withTLPHAssets: { (assets) in
             
             for asset: TLPHAsset in assets {
@@ -72,6 +84,7 @@ class NCPhotosPickerViewController: NSObject {
             
             phAssets(nil,nil)
         }
+        */
         
         viewController.didExceedMaximumNumberOfSelection = { (picker) in
             NCContentPresenter.shared.messageNotification("_info_", description: "_limited_dimension_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))

+ 1 - 0
iOSClient/Utility/CCUtility.h

@@ -251,6 +251,7 @@
 + (NSString *)getTimeIntervalSince197;
 
 + (void)extractImageVideoFromAssetLocalIdentifierForUpload:(tableMetadata *)metadata notification:(BOOL)notification completion:(void(^)(tableMetadata *newMetadata, NSString* fileNamePath))completion;
++ (void)extractLivePhotoAsset:(PHAsset*)asset filePath:(NSString *)filePath withCompletion:(void (^)(NSURL* url))completion;
 
 // ===== E2E Encrypted =====
 

+ 29 - 0
iOSClient/Utility/CCUtility.m

@@ -1612,6 +1612,35 @@
     });
 }
 
++ (void)extractLivePhotoAsset:(PHAsset*)asset filePath:(NSString *)filePath withCompletion:(void (^)(NSURL* url))completion
+{    
+    [CCUtility removeFileAtPath:filePath];
+    NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
+    PHLivePhotoRequestOptions *options = [PHLivePhotoRequestOptions new];
+    options.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat;
+    options.networkAccessAllowed = YES;
+    
+    [[PHImageManager defaultManager] requestLivePhotoForAsset:asset targetSize:[UIScreen mainScreen].bounds.size contentMode:PHImageContentModeDefault options:options resultHandler:^(PHLivePhoto * _Nullable livePhoto, NSDictionary * _Nullable info) {
+        if (livePhoto) {
+            NSArray *assetResources = [PHAssetResource assetResourcesForLivePhoto:livePhoto];
+            PHAssetResource *videoResource = nil;
+            for(PHAssetResource *resource in assetResources){
+                if (resource.type == PHAssetResourceTypePairedVideo) {
+                    videoResource = resource;
+                    break;
+                }
+            }
+            if(videoResource){
+                [[PHAssetResourceManager defaultManager] writeDataForAssetResource:videoResource toFile:fileUrl options:nil completionHandler:^(NSError * _Nullable error) {
+                    if (!error) {
+                        completion(fileUrl);
+                    } else { completion(nil); }
+                }];
+            } else { completion(nil); }
+        } else { completion(nil); }
+    }];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== E2E Encrypted =====
 #pragma --------------------------------------------------------------------------------------------