Search code examples
iosswifturlvideophotokit

How to get the url of all video files stored in photo library with photokit


I have found a lot of solutions, but all of them are implemented with ALAssetLibrary, But the assetlibrary will be depreciated in iOS 9, I do not know how to get video files in photo library, and get their url and thumbnail.


Solution

  • You could play around with the sample code Apple provides for photo kit

    Code would be something like

    PHPhotoLibrary.requestAuthorization { (status) -> Void in
                let allVidOptions = PHFetchOptions()
                allVidOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.Video.rawValue)
                allVidOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
                let allVids = PHAsset.fetchAssetsWithOptions(allVidOptions)
                for index in 0..<allVids.count {
                    //fetch Asset here
                    print(allVids[index])
                }
    
            }