0

I am using PHCachingImageManager().requestAVAssetForVideo to fetch videos from iPhone. I am not getting all the videos from my iPhone. Videos stored in Photos are being fetched not all.

How can I get all the videos stored in iPhone storage.

Here is the code.

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{


                })

                })

            }
        }
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
Rajan Kambaliya
  • 157
  • 1
  • 12

1 Answers1

0

You need to have a look inside PHFetchOptions Maybe some of your video assets are hidden?

var fetchOptions = PHFetchOptions()
fetchOptions.includeHiddenAssets = true

From the Docs-

// Whether hidden assets are included in fetch results. Defaults to NO

public var includeHiddenAssets: Bool

Hope it helps.

Community
  • 1
  • 1
Tarun Tyagi
  • 9,364
  • 2
  • 17
  • 30