I am working on AssetsPickerController
in Swift
to select multiple Videos
from Device gallery
.
Problem: When I am selecting multiple Videos
or sometimes single video
then sometimes my App
is crashing due to Empty Video Asset
. This is happening 5-10 times, out of 100 times of testing.
Code:
@IBAction func openAssetsAction(_ sender: UIButton) {
let rootListAssets = AssetsPickerController()
rootListAssets.didSelectAssets = {(assets: Array<PHAsset?>) -> () in
for i in 0..<assets.count {
let myPHAsset = assets[i]
let options = PHVideoRequestOptions()
options.deliveryMode = .highQualityFormat
options.isNetworkAccessAllowed = true
options.progressHandler = { (progress, error, stop, info) in
print("progress: \(progress)")
}
PHImageManager.default().requestAVAsset(forVideo: myPHAsset!, options: options, resultHandler: { (asset, audioMix, info) in
if let urlAsset = asset as? AVURLAsset {
let localVideoUrl = urlAsset.url
print(localVideoUrl)
}
})
}
}
let navigationController = UINavigationController(rootViewController: rootListAssets)
present(navigationController, animated: true, completion: nil)
}
I checked my best to find the similar issue in StackOverFlow and got some, they are suggesting to use isNetworkAccessAllowed
, but after setting isNetworkAccessAllowed
, still I am getting nil Asset
.