如何从图像选择器中获取 NSData?
How to get NSData from image picker?
我尝试将我照片库中所选视频的视频分享到 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
}
当我将“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
}
我尝试将我照片库中所选视频的视频分享到 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
}
当我将“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
}