@@ -76,7 +76,6 @@ - (instancetype)init:(PHAsset *)phAsset error:(NSError *__autoreleasing *)error
76
76
_file = f;
77
77
_assetData = d;
78
78
}
79
-
80
79
}
81
80
return self;
82
81
}
@@ -97,10 +96,8 @@ - (void)close {
97
96
if (PHAssetMediaTypeVideo == self.phAsset .mediaType ) {
98
97
if (_file != nil ) {
99
98
[_file closeFile ];
100
-
101
99
}
102
- [[NSFileManager defaultManager ] removeItemAtPath: _filepath error: nil ];
103
-
100
+ [[NSFileManager defaultManager ] removeItemAtPath: _filepath error: nil ];
104
101
}
105
102
}
106
103
@@ -117,50 +114,50 @@ - (int64_t)size {
117
114
}
118
115
119
116
- (NSString *)getInfo {
120
- __block NSString * filePath = nil ;
117
+ __block NSString *filePath = nil ;
121
118
if (PHAssetMediaTypeImage == self.phAsset .mediaType ) {
122
- PHImageRequestOptions *options = [PHImageRequestOptions new ];
123
- options.version = PHImageRequestOptionsVersionCurrent;
124
- options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
125
- options.resizeMode = PHImageRequestOptionsResizeModeNone;
126
- // 不支持icloud上传
127
- options.networkAccessAllowed = NO ;
128
- options.synchronous = YES ;
129
-
130
- [[PHImageManager defaultManager ] requestImageDataForAsset: self .phAsset
131
- options: options
132
- resultHandler: ^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
133
- _assetData = imageData;
134
- _fileSize = imageData.length ;
135
- _assetURL = [NSURL URLWithString: self .phAsset.localIdentifier];
136
- filePath = _assetURL.path ;
137
- }];
138
- } else if (PHAssetMediaTypeVideo == self.phAsset .mediaType ) {
139
- NSArray * assetResources = [PHAssetResource assetResourcesForAsset: self .phAsset];
140
- PHAssetResource * resource;
141
- for (PHAssetResource * assetRes in assetResources) {
142
- if (assetRes.type == PHAssetResourceTypePairedVideo || assetRes.type == PHAssetResourceTypeVideo) {
143
- resource = assetRes;
144
- }
119
+ PHImageRequestOptions *options = [PHImageRequestOptions new ];
120
+ options.version = PHImageRequestOptionsVersionCurrent;
121
+ options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
122
+ options.resizeMode = PHImageRequestOptionsResizeModeNone;
123
+ // 不支持icloud上传
124
+ options.networkAccessAllowed = NO ;
125
+ options.synchronous = YES ;
126
+
127
+ [[PHImageManager defaultManager ] requestImageDataForAsset: self .phAsset
128
+ options: options
129
+ resultHandler: ^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
130
+ _assetData = imageData;
131
+ _fileSize = imageData.length ;
132
+ _assetURL = [NSURL URLWithString: self .phAsset.localIdentifier];
133
+ filePath = _assetURL.path ;
134
+ }];
135
+ } else if (PHAssetMediaTypeVideo == self.phAsset .mediaType ) {
136
+ NSArray *assetResources = [PHAssetResource assetResourcesForAsset: self .phAsset];
137
+ PHAssetResource *resource;
138
+ for (PHAssetResource *assetRes in assetResources) {
139
+ if (assetRes.type == PHAssetResourceTypePairedVideo || assetRes.type == PHAssetResourceTypeVideo) {
140
+ resource = assetRes;
145
141
}
146
- NSString * fileName = @" tempAssetVideo.mov" ;
147
- if (resource.originalFilename ) {
148
- fileName = resource.originalFilename ;
142
+ }
143
+ NSString *fileName = @" tempAssetVideo.mov" ;
144
+ if (resource.originalFilename ) {
145
+ fileName = resource.originalFilename ;
146
+ }
147
+ PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc ] init ];
148
+ options.version = PHImageRequestOptionsVersionCurrent;
149
+ // 不支持icloud上传
150
+ options.networkAccessAllowed = NO ;
151
+ options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
152
+ NSString *PATH_VIDEO_FILE = [NSTemporaryDirectory () stringByAppendingPathComponent: fileName];
153
+ [[NSFileManager defaultManager ] removeItemAtPath: PATH_VIDEO_FILE error: nil ];
154
+ [[PHAssetResourceManager defaultManager ] writeDataForAssetResource: resource toFile: [NSURL fileURLWithPath: PATH_VIDEO_FILE] options: options completionHandler: ^(NSError *_Nullable error) {
155
+ if (error) {
156
+ filePath = nil ;
157
+ } else {
158
+ filePath = PATH_VIDEO_FILE;
149
159
}
150
- PHVideoRequestOptions * options = [[PHVideoRequestOptions alloc ] init ];
151
- options.version = PHImageRequestOptionsVersionCurrent;
152
- // 不支持icloud上传
153
- options.networkAccessAllowed = NO ;
154
- options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
155
- NSString * PATH_VIDEO_FILE = [NSTemporaryDirectory () stringByAppendingPathComponent: fileName];
156
- [[NSFileManager defaultManager ] removeItemAtPath: PATH_VIDEO_FILE error: nil ];
157
- [[PHAssetResourceManager defaultManager ] writeDataForAssetResource: resource toFile: [NSURL fileURLWithPath: PATH_VIDEO_FILE] options: options completionHandler: ^(NSError * _Nullable error) {
158
- if (error) {
159
- filePath = nil ;
160
- } else {
161
- filePath = PATH_VIDEO_FILE;
162
- }
163
- }];
160
+ }];
164
161
}
165
162
return filePath;
166
163
}
0 commit comments