2017-03-01 10 views
0

カメラで撮影しています。キャプチャした後、私はイメージ名を得ることができるようにURLを取得したいと思います。私はこれのために以下のコードを使用しています。ioSでPHPhotoLibraryからref urlを取得するには?

PHObjectPlaceholder *assetholder; 
     PHPhotoLibrary *objPhoto = [PHPhotoLibrary sharedPhotoLibrary]; 
     [objPhoto performChanges:^{ 

     PHAssetChangeRequest *assets = [PHAssetChangeRequest creationRequestForAssetFromImage:info[UIImagePickerControllerOriginalImage]]; 
     PHObjectPlaceholder *assetholder = assets.placeholderForCreatedAsset; 

     } completionHandler:^(BOOL success, NSError * _Nullable error) { 


     }]; 

イメージ名を取得できるように画像のURLを取得する方法を教えてください。同様の

+0

男 - LARGE BOUNTY - http://stackoverflow.com/questions/43791151/100-bounty-actually-get-the-filename-of-image-saved-to-photos-album-2017- ios10 – Fattie

答えて

1
PHAsset *asset = nil; 
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init]; 
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]]; 
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions]; 
if (fetchResult != nil && fetchResult.count > 0) { 
    // get last photo from Photos 
    asset = [fetchResult lastObject]; 
} 

if (asset) { 
    // get photo info from this asset 
    PHImageRequestOptions * imageRequestOptions = [[PHImageRequestOptions alloc] init]; 
    imageRequestOptions.synchronous = YES; 
    [[PHImageManager defaultManager] 
      requestImageDataForAsset:asset 
          options:imageRequestOptions 
         resultHandler:^(NSData *imageData, NSString *dataUTI, 
             UIImageOrientation orientation, 
             NSDictionary *info) 
    { 
      NSLog(@"info = %@", info); 
      if ([info objectForKey:@"PHImageFileURLKey"]) { 
       // path looks like this - 
       // file:///var/mobile/Media/DCIM/###APPLE/IMG_####.JPG 
       NSURL *path = [info objectForKey:@"PHImageFileURLKey"]; 
    }            
    }]; 
} 
+0

私の質問を勉強しても、資産資産はリセラーになっています。ギャラリーではないカメラから画像を取得していますので、nsurlはありません。 – iOSGuy

+0

@iOSGuy最新の写真の最後の写真を –

+0

ポスターはこの答えを必要としないようですが、します。ありがとう! – n4feng

関連する問題