2

In iOS 10 I start to replace asset-library to PhotoKit to manage image picker. But there is an issue.

The specific step is that app needs system camera and user shot a photo after that the delegate method imagePickerController:didFinishPickingMediaWithInfo: will be called.

Then, here is my code:

    UIImage *pickerImage = [[info objectForKey:UIImagePickerControllerOriginalImage] fixOrientation];

    PHPhotoLibrary *photoLibrary = [PHPhotoLibrary sharedPhotoLibrary];
    __block NSString *localId;
    [photoLibrary performChanges:^{
        PHAssetChangeRequest *assetChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:pickerImage];

        localId = [[assetChangeRequest placeholderForCreatedAsset] localIdentifier];

    } completionHandler:^(BOOL success, NSError * _Nullable error) {
        if (success) {
           // to get localIdentifier and reload collectionView
        }
    }];

line 1 that fixOrientation is a custom category that return UIImage instance.

Only call [PHAssetChangeRequest creationRequestForAssetFromImage:] method performs fine. However, when I want to fetch newly created photo to use [assetChangeRequest placeholderForCreatedAsset] , it shows memory leak and app crash.

Above all, any solution to fetch created photo just moment or other methods to solve that by using Photos Framework?

halfer
  • 19,824
  • 17
  • 99
  • 186
Shuhari
  • 317
  • 1
  • 2
  • 10
  • [http://stackoverflow.com/a/39202941/6547715](http://stackoverflow.com/a/39202941/6547715) <-- this solved my problem! thank you @Dinh Nhat – Shuhari Sep 17 '16 at 09:41

0 Answers0