没有使用PHCachingImageManager获取iPhone的所有视频

时间:2016-06-17 12:25:45

标签: ios swift video fetch photo-gallery

我正在使用PHCachingImageManager().requestAVAssetForVideo从iPhone上获取视频。我没有收到iPhone上的所有视频。存储在照片中的视频并非全部获取。

如何获取存储在iPhone存储中的所有视频。

这是代码。

let options = PHFetchOptions()

options.sortDescriptors = [NSSortDescriptor(key: "modificationDate",
            ascending: true)]

        let assetResults = PHAsset.fetchAssetsWithMediaType(.Video,
                                                            options: options)        

        for i in 0 ..< assetResults.count{

            let object: AnyObject = assetResults[i]

            if let asset = object as? PHAsset{

                let options = PHVideoRequestOptions()
                options.deliveryMode = .Automatic
                options.networkAccessAllowed = true
                options.version = .Current
                options.progressHandler = {(progress: Double,
                    error: NSError?,
                    stop: UnsafeMutablePointer<ObjCBool>,
                    info: [NSObject : AnyObject]?) in

            }

                /* Now get the video */
                PHCachingImageManager().requestAVAssetForVideo(asset,options: options,resultHandler: {(asset: AVAsset?,audioMix: AVAudioMix?,info: [NSObject : AnyObject]?) -> Void in dispatch_async(dispatch_get_main_queue(), {

                    /* Did we get the URL to the video? */
                    if let asset = asset as? AVURLAsset{


                })

                })

            }
        }

1 个答案:

答案 0 :(得分:0)

您需要查看PHFetchOptions内部可能隐藏了一些视频资产?

var fetchOptions = PHFetchOptions()
fetchOptions.includeHiddenAssets = true

来自文档 -

  

//隐藏资产是否包含在获取结果中。默认为NO

     

public var includeHiddenAssets:Bool

希望它有所帮助。