Bladeren bron

1.修复 icloud 图片获取不到问题

huangxiaodong 2 weken geleden
bovenliggende
commit
dd7cf35204

+ 7 - 1
创维盒子/code/Class/Set/uploadFile/PhotoPreviewViewController.m

@@ -109,7 +109,12 @@
     
         if(!model.imageData)
         {
-            [[PHImageManager defaultManager] requestImageDataForAsset:model.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+            PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
+            options.networkAccessAllowed = YES; // Allow downloading from iCloud
+            options.version = PHImageRequestOptionsVersionCurrent;
+            options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+            
+            [[PHImageManager defaultManager] requestImageDataForAsset:model.asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                     // 直接得到最终的 NSData 数据
                     if (imageData) {
                         //model.imageData = imageData;
@@ -124,6 +129,7 @@
                 
                 PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
                 options.version = PHVideoRequestOptionsVersionOriginal;
+                options.networkAccessAllowed = YES; // Allow downloading from iCloud
                 [[PHImageManager defaultManager] requestAVAssetForVideo:model.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
                     if ([asset isKindOfClass:[AVURLAsset class]]) {
                         

+ 8 - 1
创维盒子/code/Class/Set/uploadFile/uploadFileManager/backupsFileManager.m

@@ -292,7 +292,13 @@ static backupsFileManager * cur_backupsFileShareInstance = nil;
     KWeakSelf
     if(curAsset.mediaType == PHAssetMediaTypeImage){
         _curPhotosBackupsTaskMod.curUploadFileType = uploadFileTypeImage;
-        [[PHImageManager defaultManager] requestImageDataForAsset:curAsset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+        
+        PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
+        options.networkAccessAllowed = YES; // Allow downloading from iCloud
+        options.version = PHImageRequestOptionsVersionCurrent;
+        options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+        
+        [[PHImageManager defaultManager] requestImageDataForAsset:curAsset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                 // 直接得到最终的 NSData 数据
                 if (imageData) {
                     [weakSelf  afterGetImageDataFun:imageData];
@@ -316,6 +322,7 @@ static backupsFileManager * cur_backupsFileShareInstance = nil;
         //真正的视频数据
         PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
         options.version = PHVideoRequestOptionsVersionOriginal;
+        options.networkAccessAllowed = YES; // Allow downloading from iCloud
         [[PHImageManager defaultManager] requestAVAssetForVideo:curAsset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
             if ([asset isKindOfClass:[AVURLAsset class]]) {
                 

+ 19 - 3
创维盒子/code/Class/Set/uploadFile/uploadFileManager/uploadFileManager.m

@@ -178,8 +178,13 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
             NSString *imgName1 = [curModel.filename stringByReplacingOccurrencesOfString:@"." withString:@"_"];
             curModel.videoFirstImageName = [[NSString alloc] initWithFormat:@"%@.png",imgName1];
            
+            PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
+            options.networkAccessAllowed = YES; // Allow downloading from iCloud
+            options.version = PHImageRequestOptionsVersionCurrent;
+            options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+            
             //第一帧图片
-            [[PHImageManager defaultManager] requestImageDataForAsset:curModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+            [[PHImageManager defaultManager] requestImageDataForAsset:curModel.asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                     // 直接得到最终的 NSData 数据
                     if (imageData) {
                         curModel.imageData = imageData;
@@ -354,7 +359,12 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
     if(_curUploadFileDataModel.curUploadFileType == uploadFileTypeImage)
     {
         if(!_curUploadFileDataModel.imageData || _curUploadFileDataModel.imageData.length == 0){
-            [[PHImageManager defaultManager] requestImageDataForAsset:_curUploadFileDataModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+            PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
+            options.networkAccessAllowed = YES; // Allow downloading from iCloud
+            options.version = PHImageRequestOptionsVersionCurrent;
+            options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+            
+            [[PHImageManager defaultManager] requestImageDataForAsset:_curUploadFileDataModel.asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                     // 直接得到最终的 NSData 数据
                     if (imageData) {
                         self->_curUploadFileDataModel.imageData = imageData;
@@ -368,8 +378,13 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
     }
     else if(_curUploadFileDataModel.curUploadFileType == uploadFileTypeVideo){
         
+        PHImageRequestOptions *options2 = [[PHImageRequestOptions alloc] init];
+        options2.networkAccessAllowed = YES; // Allow downloading from iCloud
+        options2.version = PHImageRequestOptionsVersionCurrent;
+        options2.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+        
         //第一帧图片
-        [[PHImageManager defaultManager] requestImageDataForAsset:_curUploadFileDataModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+        [[PHImageManager defaultManager] requestImageDataForAsset:_curUploadFileDataModel.asset options:options2 resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                 // 直接得到最终的 NSData 数据
                 if (imageData) {
                     self->_curUploadFileDataModel.imageData = imageData;
@@ -380,6 +395,7 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
         //真正的视频数据
         PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
         options.version = PHVideoRequestOptionsVersionOriginal;
+        options.networkAccessAllowed = YES; // Allow downloading from iCloud
         [[PHImageManager defaultManager] requestAVAssetForVideo:_curUploadFileDataModel.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
             if ([asset isKindOfClass:[AVURLAsset class]]) {
                 

+ 13 - 2
创维盒子/code/Class/Set/uploadFile/uploadFileView/uploadFileRecordCell.m

@@ -248,7 +248,13 @@
                     self->_fileImageView.image = [UIImage imageNamed:@"uploadFile_image"];
                 }
                 else{
-                    [[PHImageManager defaultManager] requestImageDataForAsset:curUploadFileDataModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+                    
+                    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
+                    options.networkAccessAllowed = YES; // Allow downloading from iCloud
+                    options.version = PHImageRequestOptionsVersionCurrent;
+                    options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+                    
+                    [[PHImageManager defaultManager] requestImageDataForAsset:curUploadFileDataModel.asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                             // 直接得到最终的 NSData 数据
                             if (imageData) {
                                 curUploadFileDataModel.imageData = imageData;
@@ -280,7 +286,12 @@
                     curUploadFileDataModel.asset = asset;
                 }
                 
-                [[PHImageManager defaultManager] requestImageDataForAsset:curUploadFileDataModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+                PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
+                options.networkAccessAllowed = YES; // Allow downloading from iCloud
+                options.version = PHImageRequestOptionsVersionCurrent;
+                options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+                
+                [[PHImageManager defaultManager] requestImageDataForAsset:curUploadFileDataModel.asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                         // 直接得到最终的 NSData 数据
                         if (imageData) {
                             curUploadFileDataModel.imageData = imageData;

+ 8 - 1
创维盒子/code/Class/Set/uploadFile/uploadImageOrVideoViewController.m

@@ -566,7 +566,12 @@
     
     if(!model.totalBytes)
     {
-        [[PHImageManager defaultManager] requestImageDataForAsset:model.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+        PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
+        options.networkAccessAllowed = YES; // Allow downloading from iCloud
+        options.version = PHImageRequestOptionsVersionCurrent;
+        options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+        
+        [[PHImageManager defaultManager] requestImageDataForAsset:model.asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                 // 直接得到最终的 NSData 数据
                 if (imageData) {
                     //model.imageData = imageData;
@@ -588,6 +593,8 @@
             
             PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
             options.version = PHVideoRequestOptionsVersionOriginal;
+            options.networkAccessAllowed = YES; // Allow downloading from iCloud
+            
             [[PHImageManager defaultManager] requestAVAssetForVideo:model.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
                 if ([asset isKindOfClass:[AVURLAsset class]]) {
                     

+ 8 - 1
创维盒子/code/NAS/nasBackupsManager/nasBackupsManager.m

@@ -313,7 +313,13 @@
     KWeakSelf
     if(curAsset.mediaType == PHAssetMediaTypeImage){
         _curPhotosBackupsTaskMod.curUploadFileType = uploadFileTypeImage;
-        [[PHImageManager defaultManager] requestImageDataForAsset:curAsset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+        
+        PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
+        options.networkAccessAllowed = YES; // Allow downloading from iCloud
+        options.version = PHImageRequestOptionsVersionCurrent;
+        options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+        
+        [[PHImageManager defaultManager] requestImageDataForAsset:curAsset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                 // 直接得到最终的 NSData 数据
                 if (imageData) {
                     weakSelf.isGetFileDataFailType = NO;
@@ -339,6 +345,7 @@
         //真正的视频数据
         PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
         options.version = PHVideoRequestOptionsVersionOriginal;
+        options.networkAccessAllowed = YES; // Allow downloading from iCloud
         [[PHImageManager defaultManager] requestAVAssetForVideo:curAsset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
             if ([asset isKindOfClass:[AVURLAsset class]]) {
                 

+ 0 - 621
创维盒子/code/NAS/nasBackupsManager/nasBackupsManager~.m

@@ -1,621 +0,0 @@
-//
-//  nasBackupsManager.m
-//  双子星云手机
-//
-//  Created by xd h on 2024/8/29.
-//
-
-#import "nasBackupsManager.h"
-#import "nasMixBackupsManager.h"
-
-@interface nasBackupsManager ()
-/**检测任务10s后 无反馈重新开始 */
-@property (nonatomic, assign) NSInteger  taskRenewTime; //
-@property (nonatomic,strong)photosBackupsTaskModel *lastModel;//最后一次备份的数据
-
-@property (nonatomic, assign) BOOL isGetFileDataFailType;//获取图片失败
-@property (nonatomic, assign) NSUInteger getFileDataFailCount;//获取图片失败数量
-
-@end
-
-@implementation nasBackupsManager
-+ (instancetype)shareInstance {
-    static nasBackupsManager *_instance;
-    static dispatch_once_t onceToken;
-    dispatch_once(&onceToken, ^{
-        _instance = [[self alloc] init];
-    });
-    return _instance;
-}
-
-- (void)AutohandlePhotosBackupsFun
-{
-    NSString *curSdnId = ksharedAppDelegate.DeviceThirdIdMod.data.sdnId;
-    if(!_sdnId || ![curSdnId isEqualToString:_sdnId])
-    {//没有备份过 或者更换设备了
-        [self handlePhotosBackupsFun];
-    }
-    else{
-        [self checkReBackupsFileFun];
-    }
-    
-}
-
-- (void)handlePhotosBackupsFun
-{
-    _getFileDataFailCount = 0;
-    BOOL haveOpenBackups = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_photo_backups_state)];
-    if(!haveOpenBackups){
-        return;
-    }
-    
-    if(ksharedAppDelegate.DisabledFileTransferType){
-        return;
-    }
-    
-    //相册权限
-    if (![[TZImageManager manager] authorizationStatusAuthorized]){
-        [HWDataManager setBoolWithKey:Const_photo_backups_state value:NO];
-        return;
-    }
-    
-    NSString *curSdnId = ksharedAppDelegate.DeviceThirdIdMod.data.sdnId;
-    _sdnId = curSdnId;
-    
-    [photosBackupsTaskModel bg_findAsync:backups_photos_tableName limit:0 orderBy:nil desc:YES complete:^(NSArray * _Nullable array) {
-        if(!array || array.count == 0){
-            [self getAllAlbumsFun];
-            return;
-        }
-        
-        if(array.count >1){
-            [self keepDatabaseOneDataFun];
-        }
-        
-        self->_lastModel = array.firstObject;
-        
-        HLog(@"1 bg_id:%@",self->_lastModel.bg_id);
-        
-        if(self->_lastModel.isBackupsSuspendType == backupsSuspendByUser){
-            return;
-        }
-        
-        if(self->_lastModel.curBackupsState == backupsStateFail
-           ||self->_lastModel.curBackupsState == backupsStateDone){//上次备份完成
-            [self getAllAlbumsFun];
-        }
-        else{//继续上次的备份任务
-            [self handelBackupsModelFun:self->_lastModel];
-        }
-    }];
-    
-}
-
-- (void)keepDatabaseOneDataFun
-{
-    [photosBackupsTaskModel bg_deleteFirstObject:backups_photos_tableName];
-}
-
-//备份开始查询相册
-- (void)getAllAlbumsFun
-{
-    //
-    KWeakSelf
-    [[TZImageManager manager] getAllAlbums:YES allowPickingImage:YES needFetchAssets:NO completion:^(NSArray<TZAlbumModel *> *models) {
-        
-        if(models.count >= 1){
-            TZAlbumModel *curAlbumModel= models.firstObject;
-            
-            photosBackupsTaskModel * taskModel = [photosBackupsTaskModel new];
-            //taskModel.count = curAlbumModel.count;
-            //taskModel.result = curAlbumModel.result;
-            
-            taskModel.failCount = 0;
-            taskModel.didBackupsCount = 0;
-            taskModel.bg_tableName = backups_photos_tableName;
-            
-            //备份路径
-            NSString * backupsDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_backups_default_path)];
-            
-            if(!backupsDefaultPath || backupsDefaultPath.length == 0){
-                backupsDefaultPath = Const_default_backups_path;
-                [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_backups_default_path) value:backupsDefaultPath];
-            }
-            
-            NSString *lastStr= [backupsDefaultPath substringFromIndex:backupsDefaultPath.length-1];
-            if(![lastStr isEqualToString:@"/"]){
-                backupsDefaultPath = [[NSString alloc] initWithFormat:@"%@/",backupsDefaultPath];
-            }
-            
-            taskModel.backupsPath = backupsDefaultPath;
-            
-            NSMutableString *allLocalIdentifier= [NSMutableString new];
-            
-            for (PHAsset *asset in curAlbumModel.result) {
-                if (asset.localIdentifier) {
-                    if(allLocalIdentifier.length >0){
-                        [allLocalIdentifier appendString:@"&"];
-                    }
-                    [allLocalIdentifier appendString:asset.localIdentifier];
-                }
-            }
-            
-            taskModel.totalLocalIdentifier = allLocalIdentifier;
-            
-            if(self->_lastModel
-               && self->_lastModel.totalLocalIdentifier
-               && (self->_lastModel.backupsPath && [self->_lastModel.backupsPath isEqualToString:taskModel.backupsPath])){//相册备份排重
-                taskModel.PreDidBackupsCount = self->_lastModel.PreDidBackupsCount + self->_lastModel.didBackupsCount;
-                taskModel.curTaskLocalIdentifier = [weakSelf AlbumBackupsHandleNew:taskModel];
-            }
-            else{
-                taskModel.curTaskLocalIdentifier = allLocalIdentifier;
-            }
-            
-            
-            if(taskModel.curTaskLocalIdentifier.length == 0){
-                taskModel.count = 0;
-            }
-            else{
-                taskModel.count = [taskModel.curTaskLocalIdentifier componentsSeparatedByString:@"&"].count;
-            }
-            
-            HLog(@"2 bg_id:%@",taskModel.bg_id);
-            
-            [taskModel bg_saveAsync:^(BOOL isSuccess) {
-                if(!isSuccess){
-                    HLog(@"\n\nError!!!\n\n");
-                }
-                else{
-                    //[self handelBackupsModelFun:taskModel];
-                    [self handlePhotosBackupsFun];
-                }
-            }];
-        }
-    }];
-}
-
-- (NSString*)AlbumBackupsHandleNew:(photosBackupsTaskModel * )taskModel
-{
-    NSArray* curLocalIdentifierArr = [taskModel.totalLocalIdentifier componentsSeparatedByString:@"&"];
-    NSArray* preLocalIdentifierArr = [_lastModel.totalLocalIdentifier componentsSeparatedByString:@"&"];
-    
-    //处理异常 (上次没有备份完成)
-    NSInteger totalBackupNum = _lastModel.PreDidBackupsCount + _lastModel.didBackupsCount + _lastModel.failCount;
-    if(totalBackupNum < preLocalIdentifierArr.count){//preLocalIdentifierArr 改为已经备份过的
-        preLocalIdentifierArr = [preLocalIdentifierArr subarrayWithRange:NSMakeRange(0,totalBackupNum)];
-    }
-    
-    NSMutableArray *allArr = [NSMutableArray arrayWithArray:curLocalIdentifierArr];
-    
-    for (NSString*localIdentifier in preLocalIdentifierArr) {
-        for (NSString* newlocalIdentifier in allArr) {
-            if([localIdentifier isEqualToString:newlocalIdentifier]){
-                [allArr removeObject:newlocalIdentifier];
-                break;
-            }
-        }
-    }
-    
-    NSMutableString *allLocalIdentifier= [NSMutableString new];
-    for (NSString* newlocalIdentifier in allArr) {
-        if(allLocalIdentifier.length >0){
-            [allLocalIdentifier appendString:@"&"];
-        }
-        [allLocalIdentifier appendString:newlocalIdentifier];
-    }
-    
-    //把上传失败的再次加上处理
-    if (_lastModel.failTaskLocalIdentifier) {
-        [allLocalIdentifier appendString:@"&"];
-        [allLocalIdentifier appendString:_lastModel.failTaskLocalIdentifier];
-        //清空
-        _lastModel.failTaskLocalIdentifier = @"";
-    }
-    
-    return allLocalIdentifier;
-}
-
-- (void)handelBackupsModelFun:(photosBackupsTaskModel*)backupsTaskModel
-{
-    _curPhotosBackupsTaskMod = backupsTaskModel;
-    _curPhotosBackupsTaskMod.isBackupsSuspendType = backupsSuspendNone;
-    _curPhotosBackupsTaskMod.curBackupsState = backupsStateUploading;
-    
-    _curPhotosBackupsTaskMod.LocalIdentifierArr = [backupsTaskModel.curTaskLocalIdentifier componentsSeparatedByString:@"&"];
-    
-    if(_curPhotosBackupsTaskMod.LocalIdentifierArr.count == 0 ||_curPhotosBackupsTaskMod.curTaskLocalIdentifier.length == 0){
-        
-        _curPhotosBackupsTaskMod.didBackupsCount = 0;
-        _curPhotosBackupsTaskMod.curBackupsState = backupsStateDone;
-        [self RefreshDatabaseFun];
-        [self changeBackupsFileStateFun];
-        return;
-    }
-    
-    if(_curPhotosBackupsTaskMod.LocalIdentifierArr.count
-       <= (_curPhotosBackupsTaskMod.didBackupsCount + _curPhotosBackupsTaskMod.failCount))
-    {
-        _curPhotosBackupsTaskMod.curBackupsState = backupsStateDone;
-        [self RefreshDatabaseFun];
-        [self changeBackupsFileStateFun];
-        return;
-    }
-    
-    [self beginBackupsFileFun];
-}
-
-- (void)beginBackupsFileFun
-{
-    BOOL isCanUseCellular = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_canUse_Cellular_all)];
-    if(!isCanUseCellular){//不允许流量上传
-        //
-        if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN){
-            _isWifiNeedReBackupsType  = YES;
-            return;
-        }
-        
-    }
-    
-    _isWifiNeedReBackupsType  = NO;
-    _isWWANNeedReBackupsType = NO;
-    
-    self.taskRenewTime = [iTools getNowTimeStamp];
-    
-    NSInteger index = _curPhotosBackupsTaskMod.didBackupsCount + _curPhotosBackupsTaskMod.failCount;
-    
-    if(!_curPhotosBackupsTaskMod.LocalIdentifierArr){
-        _curPhotosBackupsTaskMod.LocalIdentifierArr = [_curPhotosBackupsTaskMod.curTaskLocalIdentifier componentsSeparatedByString:@"&"];
-    }
-    
-    if(index >= _curPhotosBackupsTaskMod.LocalIdentifierArr.count){
-        _curPhotosBackupsTaskMod.curBackupsState = backupsStateDone;
-        [self RefreshDatabaseFun];
-        [self changeBackupsFileStateFun];
-        _curPhotosBackupsTaskMod = nil;
-        return;
-    }
-    
-    NSString *curLocalIdentifier = _curPhotosBackupsTaskMod.LocalIdentifierArr[index];
-    _curPhotosBackupsTaskMod.curFileLocalIdentifier = curLocalIdentifier;
-    
-    if(!curLocalIdentifier || curLocalIdentifier.length == 0)
-    {
-        [self getDataWrongToChangeFailFun];
-        return;
-    }
-        
-    _curPhotosBackupsTaskMod.didUploadBytes = 0;
-    _curPhotosBackupsTaskMod.preDidUploadBytes = 0;
-    _curPhotosBackupsTaskMod.totalBytes = 0;
-    HLog(@"curLocalIdentifier:%@---%ld",curLocalIdentifier,_curPhotosBackupsTaskMod.failCount)
-    
-    //单次备份文件图片失败过多
-    if(_getFileDataFailCount >500){
-        _curPhotosBackupsTaskMod.failTaskLocalIdentifier = @"";
-        NSString *tipStr = NSLocalizedString(@"backups_get_file_error_too_many",nil);
-        [self changeBackupsFileStateToFailWith:tipStr];
-        return;
-    }
-    
-    PHFetchResult *fetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[curLocalIdentifier] options:nil];
-    PHAsset *curAsset = fetchResult.firstObject;
-    
-    NSString *fileName = [curAsset valueForKey:@"filename"];;
-   
-    if(!fileName || !curAsset){
-        _isGetFileDataFailType = YES;
-        [self getDataWrongToChangeFailFun];
-        return;
-    }
-    _curPhotosBackupsTaskMod.filename = fileName;
-    
-    KWeakSelf
-    if(curAsset.mediaType == PHAssetMediaTypeImage){
-        _curPhotosBackupsTaskMod.curUploadFileType = uploadFileTypeImage;
-        [[PHImageManager defaultManager] requestImageDataForAsset:curAsset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
-                // 直接得到最终的 NSData 数据
-                if (imageData) {
-                    weakSelf.isGetFileDataFailType = NO;
-                    [weakSelf  afterGetImageDataFun:imageData];
-                }
-                else{
-                    weakSelf.isGetFileDataFailType = YES;
-                    [weakSelf getDataWrongToChangeFailFun];
-                }
-        }];
-    }
-    else{
-        _curPhotosBackupsTaskMod.curUploadFileType = uploadFileTypeVideo;
-        
-        //判断文件是否在app内
-       BOOL didSaveFile = [cachesFileManager  checkFileIsSaveState:_curPhotosBackupsTaskMod.filename withType:uploadFileTypeVideo];
-        
-        if(didSaveFile){
-            [self afterGetVideoDataFun];
-            return;
-        }
-        
-        //真正的视频数据
-        PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
-        options.version = PHVideoRequestOptionsVersionOriginal;
-        [[PHImageManager defaultManager] requestAVAssetForVideo:curAsset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
-            if ([asset isKindOfClass:[AVURLAsset class]]) {
-                
-                AVURLAsset* urlAsset = (AVURLAsset*)asset;
-                
-                BOOL isSuc = [cachesFileManager copyVideoItemAtPath:[urlAsset.URL path] fileName:self->_curPhotosBackupsTaskMod.filename error:nil];
-        
-                if (isSuc) {
-                    weakSelf.isGetFileDataFailType = NO;
-                    [weakSelf  afterGetVideoDataFun];
-                }
-                else{
-                    weakSelf.isGetFileDataFailType = YES;
-                    [weakSelf getDataWrongToChangeFailFun];
-                }
-            }
-            else{
-                weakSelf.isGetFileDataFailType = YES;
-                [weakSelf getDataWrongToChangeFailFun];
-            }
-        }];
-    }
-    
-}
-
-- (void)getDataWrongToChangeFailFun
-{
-    [self deleteVideoFun];
-    _curPhotosBackupsTaskMod.failCount += 1;
-    
-    if(_isGetFileDataFailType){
-        _getFileDataFailCount += 1;
-    }
-    
-    [self RefreshDatabaseFun];
-    
-    if(_curPhotosBackupsTaskMod.curBackupsState == backupsStateSuspend){
-        return;
-    }
-    
-    [self beginBackupsFileFun];
-}
-
-#pragma mark 备份失败 待添加重试逻辑
-- (void)changeBackupsFileStateToFailWith:(NSString*)errorStr
-{
-    [self deleteVideoFun];
-    _curPhotosBackupsTaskMod.curBackupsState = backupsStateFail;
-    _curPhotosBackupsTaskMod.backupsTipMsg = errorStr;
-    [self RefreshDatabaseFun];
-    [self changeBackupsFileStateFun];
-}
-
-#pragma mark 1.4.2的失败处理
-- (void)changeBackupsFileStateToFailWithAfter142:(NSString*)errorStr
-{
-    if(_curPhotosBackupsTaskMod.oneFileFailCount <= 3){
-        _curPhotosBackupsTaskMod.oneFileFailCount ++;
-        [[nasMixBackupsManager shareManager] cancelUploadAllTaskFun];
-        
-        //重新开始
-        [self beginBackupsFileFun];
-    }
-    else{
-        
-        NSString * failTaskLocalIdentifier = nil;
-        if(_curPhotosBackupsTaskMod.failTaskLocalIdentifier && _curPhotosBackupsTaskMod.failTaskLocalIdentifier.length > 0){
-            failTaskLocalIdentifier = [[NSString alloc] initWithFormat:@"%@&%@",_curPhotosBackupsTaskMod.failTaskLocalIdentifier,_curPhotosBackupsTaskMod.curFileLocalIdentifier];
-        }
-        else{
-            failTaskLocalIdentifier = [[NSString alloc] initWithFormat:@"%@",_curPhotosBackupsTaskMod.curFileLocalIdentifier];
-        }
-        
-        _curPhotosBackupsTaskMod.oneFileFailCount = 0;
-        [self getDataWrongToChangeFailFun];
-    }
-}
-
-- (void)RefreshDatabaseFun
-{
-    HLog(@"3 bg_id:%@",_curPhotosBackupsTaskMod.bg_id);
-    [_curPhotosBackupsTaskMod bg_saveOrUpdateAsync:^(BOOL isSuccess) {
-                if(isSuccess){
-                }
-    }];
-}
-
-- (void)afterGetImageDataFun:(NSData*)imageData
-{
-    _curPhotosBackupsTaskMod.imageData = imageData;
-    _curPhotosBackupsTaskMod.didUploadBytes = 0;
-    _curPhotosBackupsTaskMod.totalBytes = [imageData length];
-    //[[webSocketManager shareInstance] beginGotoBackupsFileFunBy:_curPhotosBackupsTaskMod];
-    [self RefreshDatabaseFun];
-    [self changeBackupsFileStateFun];
-    [self realbBeginUploadwithFrpFun];
-}
-
-- (void)deleteVideoFun
-{
-    if(_curPhotosBackupsTaskMod.curUploadFileType == uploadFileTypeVideo){
-        [cachesFileManager removeItemAtPath:_curPhotosBackupsTaskMod.filename type:uploadFileTypeVideo error:nil];
-    }
-}
-
-- (void)afterGetVideoDataFun
-{
-    NSString *filePath = [cachesFileManager getFilePathWithName:_curPhotosBackupsTaskMod.filename type:uploadFileTypeVideo]; // 文件路径
-    
-    NSFileManager *manager0 = [NSFileManager defaultManager];
-    if([manager0 fileExistsAtPath:filePath]) {
-        NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath]; // 创建文件句柄
-        
-        if (fileHandle) {
-            long long endOfFile = [fileHandle seekToEndOfFile];
-            
-            _curPhotosBackupsTaskMod.didUploadBytes = 0;
-            _curPhotosBackupsTaskMod.totalBytes = endOfFile;
-            [fileHandle closeFile];
-        }
-        
-    }
-    
-    
-    //[[webSocketManager shareInstance] beginGotoBackupsFileFunBy:_curPhotosBackupsTaskMod];
-    [self RefreshDatabaseFun];
-    [self changeBackupsFileStateFun];
-    [self realbBeginUploadwithFrpFun];
-}
-
-#pragma mark 转frp上传
-- (void)realbBeginUploadwithFrpFun{
-    
-    uploadFileDataModel *fileModel = [uploadFileDataModel new];
-    fileModel.curUploadFileType = _curPhotosBackupsTaskMod.curUploadFileType;
-    fileModel.filename = _curPhotosBackupsTaskMod.filename;
-    fileModel.totalBytes = _curPhotosBackupsTaskMod.totalBytes;
-    fileModel.didUploadBytes = 0;
-    fileModel.preDidUploadBytes = 0;
-    fileModel.localIdentifier = _curPhotosBackupsTaskMod.curTaskLocalIdentifier;
-    fileModel.curUploadStateType = uploadStateUploading;
-    fileModel.savePath = _curPhotosBackupsTaskMod.backupsPath;
-    //fileModel.taskId
-    //@property (nonatomic, retain) NSData *_Nullable imageData;//image or video
-    if(_curPhotosBackupsTaskMod.curUploadFileType == uploadFileTypeImage){
-        fileModel.imageData = _curPhotosBackupsTaskMod.imageData;
-    }
-  
-    
-    [[nasMixBackupsManager shareManager] addBackupsWithModels:@[fileModel]];
-}
-
-- (void)backupsFileDoneFun
-{
-    [self deleteVideoFun];
-    _curPhotosBackupsTaskMod.didBackupsCount += 1;
-    
-    _curPhotosBackupsTaskMod.oneFileFailCount = 0;
-    
-//    if(!_curPhotosBackupsTaskMod.didBackupsOneFileType)
-//    {
-//        _curPhotosBackupsTaskMod.curTaskBackupsCount += 1;
-//    }
-    
-    [self RefreshDatabaseFun];
-    [self changeBackupsFileStateFun];
-    
-    if(_curPhotosBackupsTaskMod.curBackupsState == backupsStateSuspend){
-        return;
-    }
-    
-    //延时 进度条视觉效果
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-        [self beginBackupsFileFun];
-    });
-    
-    
-}
-
-//修改文件上传的状态
-- (void)changeBackupsFileStateFun
-{
-    self.taskRenewTime = [iTools getNowTimeStamp];
-    
-    [[NSNotificationCenter defaultCenter] postNotificationName:backupsFileRefreshNotification object:_curPhotosBackupsTaskMod];
-}
-
-- (void)suspendBackupsFileFun
-{
-    if(!_curPhotosBackupsTaskMod){
-        return;
-    }
-    
-    _curPhotosBackupsTaskMod.curBackupsState = backupsStateSuspend;
-    _curPhotosBackupsTaskMod.backupsTipMsg = NSLocalizedString(@"File_backups_Record_tip_Suspend",nil);
-    
-    [[nasMixBackupsManager shareManager] cancelUploadAllTaskFun];
-    
-    [_curPhotosBackupsTaskMod bg_saveOrUpdateAsync:^(BOOL isSuccess) {
-        if(isSuccess){
-            [self changeBackupsFileStateFun];
-        }
-    }];
-    
-}
-
-//文件重新备份
-- (void)reBackupsFileFunBy:(photosBackupsTaskModel*)model
-{
-    model.isBackupsSuspendType = backupsSuspendNone;
-    model.curBackupsState = backupsStateUploading;
-    _curPhotosBackupsTaskMod = model;
-        
-    [self RefreshDatabaseFun];
-    [self changeBackupsFileStateFun];
-    
-    [self beginBackupsFileFun];
-    
-//    [_curPhotosBackupsTaskMod bg_saveOrUpdateAsync:^(BOOL isSuccess) {
-//        if(isSuccess){
-//            [self beginBackupsFileFun];
-//        }
-//    }];
-    
-}
-
-//文件重新备份
-- (void)reBackupsFileFun
-{
-    [self handlePhotosBackupsFun];
-    
-    //if(_curPhotosBackupsTaskMod.curBackupsState != backupsStateUploading)
-    if(self->_lastModel.curBackupsState != backupsStateUploading){
-        if(self->_lastModel.curBackupsState == backupsStateFail
-           ||self->_lastModel.curBackupsState == backupsStateDone){//上次备份完成
-            [self getAllAlbumsFun];
-        }
-        else{//继续上次的备份任务
-            [self handelBackupsModelFun:self->_lastModel];
-        }
-    }
-}
-
-//检查是否需要重新备份
-- (void)checkReBackupsFileFun
-{
-    if(!_curPhotosBackupsTaskMod){
-        return;
-    }
-    
-    if(_curPhotosBackupsTaskMod.curBackupsState != backupsStateUploading){
-        return;
-    }
-    
-    NSInteger curTime = [iTools getNowTimeStamp];
-    
-    if(self.taskRenewTime == 0){
-        return;
-    }
-    
-    if(curTime - self.taskRenewTime < 10){
-        return;
-    }
-    
-    [self beginBackupsFileFun];
-}
-
-//检查是否在备份中
-- (BOOL)checkBackupsingFun{
-    if(!_curPhotosBackupsTaskMod){
-        return NO;
-    }
-    
-    if(_curPhotosBackupsTaskMod.curBackupsState == backupsStateSuspend){
-        return NO;
-    }
-    
-    return YES;
-}
-@end

+ 7 - 1
创维盒子/code/NAS/nasBackupsManager/nasMixBackupsManager.m

@@ -282,7 +282,12 @@
                     operation.fileModel.asset = asset;
                 }
                 
-                [[PHImageManager defaultManager] requestImageDataForAsset:operation.fileModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+                PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
+                options.networkAccessAllowed = YES; // Allow downloading from iCloud
+                options.version = PHImageRequestOptionsVersionCurrent;
+                options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+                
+                [[PHImageManager defaultManager] requestImageDataForAsset:operation.fileModel.asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                         // 直接得到最终的 NSData 数据
                         if (imageData) {
                             operation.fileModel.imageData = imageData;
@@ -337,6 +342,7 @@
             //真正的视频数据
             PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
             options.version = PHVideoRequestOptionsVersionOriginal;
+            options.networkAccessAllowed = YES; // Allow downloading from iCloud
             [[PHImageManager defaultManager] requestAVAssetForVideo:operation.fileModel.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
                 if ([asset isKindOfClass:[AVURLAsset class]]) {
                     

+ 7 - 1
创维盒子/code/NAS/nasUploadManager/nasMixUploadManager.m

@@ -391,7 +391,12 @@
                     operation.fileModel.asset = asset;
                 }
                 
-                [[PHImageManager defaultManager] requestImageDataForAsset:operation.fileModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+                PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
+                options.networkAccessAllowed = YES; // Allow downloading from iCloud
+                options.version = PHImageRequestOptionsVersionCurrent;
+                options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+                
+                [[PHImageManager defaultManager] requestImageDataForAsset:operation.fileModel.asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                         // 直接得到最终的 NSData 数据
                         if (imageData) {
                             operation.fileModel.imageData = imageData;
@@ -452,6 +457,7 @@
             //真正的视频数据
             PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
             options.version = PHVideoRequestOptionsVersionOriginal;
+            options.networkAccessAllowed = YES; // Allow downloading from iCloud
             [[PHImageManager defaultManager] requestAVAssetForVideo:operation.fileModel.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
                 if ([asset isKindOfClass:[AVURLAsset class]]) {
                     

+ 7 - 1
创维盒子/code/NAS/nasUploadManager/nasUploadFileManager.m

@@ -179,7 +179,13 @@
             curModel.videoFirstImageName = [[NSString alloc] initWithFormat:@"%@.png",imgName1];
            
             //第一帧图片
-            [[PHImageManager defaultManager] requestImageDataForAsset:curModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+            
+            PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
+            options.networkAccessAllowed = YES; // Allow downloading from iCloud
+            options.version = PHImageRequestOptionsVersionCurrent;
+            options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
+            
+            [[PHImageManager defaultManager] requestImageDataForAsset:curModel.asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                     // 直接得到最终的 NSData 数据
                     if (imageData) {
                         curModel.imageData = imageData;