Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get path from phAsset #302

Open
singh-karan-7 opened this issue Dec 21, 2019 · 0 comments
Open

Unable to get path from phAsset #302

singh-karan-7 opened this issue Dec 21, 2019 · 0 comments

Comments

@singh-karan-7
Copy link

I want to get the path of selected images. But, using phAsset from metadata returns nil. I tried the following:
None of the ways in the following function worked.
` func getImagesFromAsset(asset: PHAsset) -> URL? {
var finalURL: URL?

    let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions()
    options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData) -> Bool in
        return true
    }

// PHImageManager.default().requestImage(for: asset, targetSize: CGSize(width: 600, height: 600), contentMode: .aspectFill, options: nil, resultHandler: { (image, info) in
// //resultHandler have info ([AnyHashable: Any])
// print(info!["PHImageFileURLKey"])
// finalURL = info!["PHImageFileURLKey"] as! URL
//
// })

    let imageRequestOptions = PHImageRequestOptions()
    PHImageManager.default().requestImageData(for: asset, options: imageRequestOptions, resultHandler: { imageData, dataUTI, orientation, info in
      if let info = info {
        print("info = \(info)")
      }
      if info?["PHImageFileURLKey"] != nil {

        let path = info?["PHImageFileURLKey"] as? URL
         print(path) //here you get complete URL


        // if you want to save image in document see this.
       // self.saveimageindocument(imageData, withimagename: "DEMO")
      }
    })
    
    asset.requestContentEditingInput(with: options) { (editingInput, info) in
        if asset.mediaType == .image {
            if let strURL = editingInput?.fullSizeImageURL?.absoluteString {
                print("IMAGE URL: ", strURL)
            } else {
                print("nill")
            }
        }
    }
    asset.requestContentEditingInput(with: options) { (eidtingInput, info) in
        
        if #available(iOS 11.0, *) {
            let imgUrl = info[UIImagePickerController.InfoKey.imageURL] as? URL
        } else {
            // Fallback on earlier versions
        }
        print("Here")

// print(imgUrl)
print(info)
print(eidtingInput)

      if let input = eidtingInput, let imgURL = input.fullSizeImageURL {
         // imgURL
        print(imgURL)
        finalURL = imgURL
      }
    }
    return finalURL
}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant