我目前正致力于将照片和视频上传到我的应用。到目前为止,我已完成照片上传,但当我在iPad上访问我的图书馆时,我看不到我的视频或选择它们。谁知道我怎么做到这一点?
到目前为止,这是我的代码:
Class SixthViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate
{
@IBOutlet weak var logUd: UIButton!
@IBOutlet weak var myImageView: UIImageView!
@IBOutlet weak var vælgFiler: UIButton!
var SelectedAssets = [PHAsset]()
var PhotoArray = [UIImage]()
@IBOutlet weak var upload: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
logUd.backgroundColor = UIColor.white
logUd.layer.cornerRadius = 7
logUd.setTitleColor(UIColor.black, for: .normal)
vælgFiler.backgroundColor = UIColor.white
vælgFiler.layer.cornerRadius = 7
vælgFiler.setTitleColor(UIColor.black, for: .normal)
upload.backgroundColor = UIColor.white
upload.layer.cornerRadius = 7
upload.setTitleColor(UIColor.black, for: .normal)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func logUd(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
@IBAction func upload(_ sender: Any) {
//myImageUploadRequest()
}
@IBAction func vælgFiler(_ sender: Any) {
let vc = BSImagePickerViewController()
self.bs_presentImagePickerController(vc, animated: true,
select: { (assets: PHAsset) -> Void in
},deselect: { (asset: PHAsset) -> Void in
},cancel: {(assets: [PHAsset]) -> Void in
}, finish: {(assets: [PHAsset]) -> Void in
for i in 0..<assets.count{
self.SelectedAssets.append(assets[i])
}
self.convertAssetToImages()
}, completion: nil)
}
func convertAssetToImages() -> Void {
if SelectedAssets.count != 0{
for i in 0..<SelectedAssets.count{
let manager = PHImageManager.default()
let option = PHImageRequestOptions()
var thumbnail = UIImage()
option.isSynchronous = true
manager.requestImage(for: SelectedAssets[i], targetSize: CGSize(width: 200, height: 200), contentMode: .aspectFill, options: option, resultHandler: {(result, info)->Void in thumbnail = result!
})
let data = UIImageJPEGRepresentation(thumbnail, 0.7)
let newImage = UIImage(data: data!)
self.PhotoArray.append(newImage! as UIImage)
}
self.myImageView.animationImages = self.PhotoArray
self.myImageView.animationDuration = 10.0
self.myImageView.startAnimating()
}
print("complete photo array \(self.PhotoArray)")
}
答案 0 :(得分:0)
如果您希望BSImagePicker
能够显示视频和照片,则必须更改图书馆的来源。
有一个名为PhotosViewController
的文件显示照片网格。内部采用initializePhotosDataSource
方式过滤掉所有视频,仅显示带有以下内容的照片
fetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue)
如果你要从fetchOptions
中删除这个谓词,那么图书馆会(我已经测试了这个)显示视频和照片......