【问题标题】:UIImagePickerController doesn't return a live photo in iOS 13UIImagePickerController 在 iOS 13 中不返回实时照片
【发布时间】:2019-10-12 14:56:34
【问题描述】:

我的代码在 iOS 13 中停止工作。在我的 UIImagePickerController 委托中,我查看返回的媒体类型(用户选择的事物类型)是否是实时照片。如果是,我使用.livePhoto 键来获取PHLivePhoto。这曾经奏效。但在 iOS 13 中,此键的值始终为 nil。如何获取用户选择的实况照片?

【问题讨论】:

    标签: ios uiimagepickercontroller ios13 phlivephoto


    【解决方案1】:

    我认为这种行为变化是一个错误。但是,如果您有权限访问用户的照片库,您可以使用.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()
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-15
      • 1970-01-01
      • 1970-01-01
      • 2018-07-15
      • 2014-09-20
      • 1970-01-01
      相关资源
      最近更新 更多