@@ -287,9 +287,9 @@ __block void (^takephotoBlock) (void) = ^(void){
287287 NSData * imageData = UIImageJPEGRepresentation (fixJpeg, 1 .0f );
288288 CGImageSourceRef fixSource = CGImageSourceCreateWithData ((__bridge CFDataRef) imageData, NULL );
289289 NSString *tmpName = NSProcessInfo .processInfo .globallyUniqueString ;
290- __block NSURL *tmpUrl = [NSURL URLWithString: [NSString stringWithFormat: @" file://%@%@ .jpg" , NSTemporaryDirectory (), tmpName]];
291-
290+ __block NSURL *tmpUrl = [NSURL URLWithString: [NSString stringWithFormat: @" file://%@%@ .jpeg" , NSTemporaryDirectory (), tmpName]];
292291 CGImageDestinationRef destination = CGImageDestinationCreateWithURL ((__bridge CFURLRef) tmpUrl, kUTTypeJPEG , 1 , nil );
292+
293293 CGImageDestinationAddImageFromSource (destination, fixSource, 0 , (__bridge CFDictionaryRef) meta);
294294 CGImageDestinationFinalize (destination);
295295 if (source) {
@@ -301,28 +301,19 @@ __block void (^takephotoBlock) (void) = ^(void){
301301 if (destination) {
302302 CFRelease (destination);
303303 }
304- __block NSString *localId = nil ;
305- PHFetchResult *collectonResuts = [PHCollectionList fetchTopLevelUserCollectionsWithOptions: nil ];
306- __block PHAssetCollection *assetCollection = nil ;
307- [collectonResuts enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
308- assetCollection = obj;
309- }];
310-
304+ __block PHObjectPlaceholder *placeHolder;
311305 [[PHPhotoLibrary sharedPhotoLibrary ] performChanges: ^{
312306 PHAssetChangeRequest *assetRequest = [PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL: tmpUrl];
313- PHAssetCollectionChangeRequest *collectonRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection: assetCollection];
314- PHObjectPlaceholder *placeHolder = [assetRequest placeholderForCreatedAsset ];
315- [collectonRequest addAssets: @[placeHolder]];
316- localId = placeHolder.localIdentifier ;
307+ placeHolder = [assetRequest placeholderForCreatedAsset ];
317308 } completionHandler: ^(BOOL success, NSError *error) {
318- if (error ) {
309+ if (!success ) {
319310 err = [DPHostUtils throwsErrorCode: DConnectMessageErrorCodeUnknown message: error.localizedDescription];
320311 completionHandler (nil , err);
321312 return ;
322313 }
323314 [[NSFileManager defaultManager ] removeItemAtURL: tmpUrl error: &err];
324315
325- completionHandler ([NSURL URLWithString: localId ], err);
316+ completionHandler ([NSURL URLWithString: placeHolder.localIdentifier ], err);
326317 }];
327318
328319 }];
0 commit comments