我的代码在iOS 13中停止工作。在我的UIImagePickerController委托中,我查看返回的媒体类型(用户选择的类型)是否是实时照片。如果是,我使用.livePhoto密钥来获取PHLivePhoto。这曾经很管用。但在iOS 13中,此键的值始终为nil。如何获取用户选择的实时照片?
发布于 2019-10-12 22:57:51
我认为这种行为上的改变是一个bug。但是,如果您有权限访问用户的图片库,则可以使用.phAsset值(一个PHAsset )直接从图片库获取相应的PHLivePhoto。
let asset = info[.phAsset] as? PHAsset
if let style = asset?.playbackStyle {
switch style {
case .livePhoto:
// hmm, I'm getting .livePhoto but live _is_ nil!
if live != nil {
self.showLivePhoto(live!)
} else {
print("live is nil!")
// well then I'll fetch it myself, said the little red hen
if let asset = asset {
PHImageManager.default().requestLivePhoto(
for: asset, targetSize: self.redView.bounds.size,
contentMode: .aspectFit, options: nil) {
photo, info in
if let photo = photo {
self.showLivePhoto(photo)
}
}
}
}
// ... other cases ...
@unknown default: fatalError()
}
}https://stackoverflow.com/questions/58355403
复制相似问题