how to get path of picture taken by camera ios swift

僤鯓⒐⒋嵵緔 提交于 2019-11-29 14:22:18

The image you have taken is not saved and has not any name yet. You need to save the image before you can get the path for the image. That´s why it returns nil.

If you select an image from the image library instead of taking one with the camera you´ll get a path.

After you saved the image into the Photos Album, you can get the path in response callback

func saveImage(image: UIImage, completion: @escaping (Error?) -> ()) {
   UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(path:didFinishSavingWithError:contextInfo:)), nil)
}

@objc private func image(path: String, didFinishSavingWithError error: NSError?, contextInfo: UnsafeMutableRawPointer?) {
    debugPrint(path) // That's the path you want
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!