|
@@ -868,113 +868,107 @@
|
|
|
// IMAGE
|
|
|
if (assetMediaType == PHAssetMediaTypeImage) {
|
|
|
|
|
|
- @autoreleasepool {
|
|
|
+ __block PHAsset *asset = result[0];
|
|
|
+ __block NSError *error = nil;
|
|
|
|
|
|
- __block PHAsset *asset = result[0];
|
|
|
- __block NSError *error = nil;
|
|
|
+ PHImageRequestOptions *options = [PHImageRequestOptions new];
|
|
|
+ options.networkAccessAllowed = YES; // iCloud
|
|
|
|
|
|
- PHImageRequestOptions *options = [PHImageRequestOptions new];
|
|
|
- options.networkAccessAllowed = YES; // iCloud
|
|
|
-
|
|
|
- [[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
|
|
|
+ [[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
|
|
|
|
|
|
- [imageData writeToFile:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName] options:NSDataWritingAtomic error:&error];
|
|
|
+ [imageData writeToFile:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName] options:NSDataWritingAtomic error:&error];
|
|
|
|
|
|
- if (error) {
|
|
|
+ if (error) {
|
|
|
|
|
|
- // Delete record on Table Auto Upload
|
|
|
- if ([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll])
|
|
|
- [[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:assetLocalIdentifier];
|
|
|
+ // Delete record on Table Auto Upload
|
|
|
+ if ([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll])
|
|
|
+ [[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:assetLocalIdentifier];
|
|
|
|
|
|
- // Activity
|
|
|
- [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), error.description] type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
+ // Activity
|
|
|
+ [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), error.description] type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
|
|
|
- // Error for uploadFileFailure
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
- [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), error.description] errorCode:error.code];
|
|
|
- });
|
|
|
+ // Error for uploadFileFailure
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
+ [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), error.description] errorCode:error.code];
|
|
|
+ });
|
|
|
|
|
|
- } else {
|
|
|
+ } else {
|
|
|
|
|
|
- //OK
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- [self upload:fileName serverUrl:serverUrl cryptated:cryptated template:NO onlyPlist:NO fileNameTemplate:nil assetLocalIdentifier:assetLocalIdentifier session:session taskStatus:taskStatus selector:selector selectorPost:selectorPost errorCode:errorCode delegate:delegate];
|
|
|
- });
|
|
|
- }
|
|
|
- }];
|
|
|
- }
|
|
|
+ //OK
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [self upload:fileName serverUrl:serverUrl cryptated:cryptated template:NO onlyPlist:NO fileNameTemplate:nil assetLocalIdentifier:assetLocalIdentifier session:session taskStatus:taskStatus selector:selector selectorPost:selectorPost errorCode:errorCode delegate:delegate];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }];
|
|
|
}
|
|
|
|
|
|
// VIDEO
|
|
|
if (assetMediaType == PHAssetMediaTypeVideo) {
|
|
|
|
|
|
- @autoreleasepool {
|
|
|
-
|
|
|
- __block PHAsset *asset = result[0];
|
|
|
- __block NSError *error = nil;
|
|
|
+ __block PHAsset *asset = result[0];
|
|
|
+ __block NSError *error = nil;
|
|
|
|
|
|
- PHVideoRequestOptions *options = [PHVideoRequestOptions new];
|
|
|
- options.networkAccessAllowed = YES; // iCloud
|
|
|
+ PHVideoRequestOptions *options = [PHVideoRequestOptions new];
|
|
|
+ options.networkAccessAllowed = YES; // iCloud
|
|
|
|
|
|
- [[PHImageManager defaultManager] requestPlayerItemForVideo:asset options:options resultHandler:^(AVPlayerItem * _Nullable playerItem, NSDictionary * _Nullable info) {
|
|
|
+ [[PHImageManager defaultManager] requestPlayerItemForVideo:asset options:options resultHandler:^(AVPlayerItem * _Nullable playerItem, NSDictionary * _Nullable info) {
|
|
|
|
|
|
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName]])
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName] error:nil];
|
|
|
+ if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName]])
|
|
|
+ [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName] error:nil];
|
|
|
|
|
|
- AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:playerItem.asset presetName:AVAssetExportPresetHighestQuality];
|
|
|
+ AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:playerItem.asset presetName:AVAssetExportPresetHighestQuality];
|
|
|
|
|
|
- if (exportSession) {
|
|
|
+ if (exportSession) {
|
|
|
|
|
|
- exportSession.outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName]];
|
|
|
- exportSession.outputFileType = AVFileTypeQuickTimeMovie;
|
|
|
+ exportSession.outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName]];
|
|
|
+ exportSession.outputFileType = AVFileTypeQuickTimeMovie;
|
|
|
|
|
|
- [exportSession exportAsynchronouslyWithCompletionHandler:^{
|
|
|
+ [exportSession exportAsynchronouslyWithCompletionHandler:^{
|
|
|
|
|
|
- if (AVAssetExportSessionStatusCompleted == exportSession.status) {
|
|
|
+ if (AVAssetExportSessionStatusCompleted == exportSession.status) {
|
|
|
|
|
|
- // OK
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- [self upload:fileName serverUrl:serverUrl cryptated:cryptated template:NO onlyPlist:NO fileNameTemplate:nil assetLocalIdentifier:assetLocalIdentifier session:session taskStatus:taskStatus selector:selector selectorPost:selectorPost errorCode:errorCode delegate:delegate];
|
|
|
- });
|
|
|
+ // OK
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [self upload:fileName serverUrl:serverUrl cryptated:cryptated template:NO onlyPlist:NO fileNameTemplate:nil assetLocalIdentifier:assetLocalIdentifier session:session taskStatus:taskStatus selector:selector selectorPost:selectorPost errorCode:errorCode delegate:delegate];
|
|
|
+ });
|
|
|
|
|
|
- } else if (AVAssetExportSessionStatusFailed == exportSession.status) {
|
|
|
+ } else if (AVAssetExportSessionStatusFailed == exportSession.status) {
|
|
|
|
|
|
- // Delete record on Table Auto Upload
|
|
|
- if ([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll])
|
|
|
- [[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:assetLocalIdentifier];
|
|
|
+ // Delete record on Table Auto Upload
|
|
|
+ if ([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll])
|
|
|
+ [[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:assetLocalIdentifier];
|
|
|
|
|
|
- // Activity
|
|
|
- [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), error.description] type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
+ // Activity
|
|
|
+ [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), error.description] type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
|
|
|
- // Error for uploadFileFailure
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
- [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), exportSession.error.description] errorCode:exportSession.error.code];
|
|
|
- });
|
|
|
-
|
|
|
- } else {
|
|
|
- NSLog(@"Export Session Status: %ld", (long)exportSession.status);
|
|
|
- }
|
|
|
- }];
|
|
|
+ // Error for uploadFileFailure
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
+ [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), exportSession.error.description] errorCode:exportSession.error.code];
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+ NSLog(@"Export Session Status: %ld", (long)exportSession.status);
|
|
|
+ }
|
|
|
+ }];
|
|
|
|
|
|
- } else {
|
|
|
+ } else {
|
|
|
|
|
|
- // Delete record on Table Auto Upload
|
|
|
- if ([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll])
|
|
|
- [[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:assetLocalIdentifier];
|
|
|
+ // Delete record on Table Auto Upload
|
|
|
+ if ([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll])
|
|
|
+ [[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:assetLocalIdentifier];
|
|
|
|
|
|
- // Activity
|
|
|
- [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), error.description] type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
+ // Activity
|
|
|
+ [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), error.description] type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
|
|
|
- // Error for uploadFileFailure
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
- [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), exportSession.error.description] errorCode:exportSession.error.code];
|
|
|
- });
|
|
|
- }
|
|
|
- }];
|
|
|
- }
|
|
|
+ // Error for uploadFileFailure
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
+ [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), exportSession.error.description] errorCode:exportSession.error.code];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }];
|
|
|
}
|
|
|
}
|
|
|
|