如何从图像选择器中获取 NSData?
Posted
技术标签:
【中文标题】如何从图像选择器中获取 NSData?【英文标题】:How to get NSData from image picker? 【发布时间】:2021-01-06 23:20:34 【问题描述】:我尝试将我照片库中选定视频中的视频分享到 Instagram 故事
func shareToInstagramStories(video: NSData)
// NOTE: you need a different custom URL scheme for Stories, instagram-stories, add it to your Info.plist!
guard let instagramUrl = URL(string: "instagram-stories://share") else
return
if UIApplication.shared.canOpenURL(instagramUrl)
let pasterboardItems = [["com.instagram.sharedSticker.backgroundVideo": video as Any]]
UIPasteboard.general.setItems(pasterboardItems)
UIApplication.shared.open(instagramUrl)
else
//fail
这是我的图像选择器功能
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
self.dismiss(animated: true, completion: nil)
videoURL = info[UIImagePickerController.InfoKey.init(rawValue: "UIImagePickerControllerReferenceURL")] as? NSURL
【问题讨论】:
referenceURL 已弃用。顺便说一句,对于 ios 14 或更高版本,您应该使用 phpickerViewController 【参考方案1】:当我将“UIImagePickerControllerReferenceURL”更改为“UIImagePickerControllerMediaURL”时,它完全起作用了
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
self.dismiss(animated: true, completion: nil)
videoURL = info[UIImagePickerController.InfoKey.init(rawValue: "UIImagePickerControllerMediaURL")] as? URL
【讨论】:
以上是关于如何从图像选择器中获取 NSData?的主要内容,如果未能解决你的问题,请参考以下文章