How To get Image URL From PHAsset? Is it possible To save Image using PHAsset URL to document Directory?

Keyur picture Keyur · Jun 10, 2017 · Viewed 12k times · Source

I used

  `NSURL *urlA = [info valueForKey:@"PHImageFileURLKey"];`

but when i try to save image using URL then URL is nil.

 `NSData *pngData =[NSData dataWithContentsOfURL:urlA options:NSDataReadingMapped error:nil];`

Answer

a_tuo picture a_tuo · Jun 10, 2017

You can get the imageURL from PHContentEditingInput:

Swift:

asset.requestContentEditingInput(with: PHContentEditingInputRequestOptions()) { (eidtingInput, info) in
  if let input = eidtingInput, let imgURL = input.fullSizeImageURL {
     // imgURL 
  }
}

Objective-C:

[asset requestContentEditingInputWithOptions:[PHContentEditingInputRequestOptions new] completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
    NSURL *imageURL = contentEditingInput.fullSizeImageURL;
}];