Last active
February 13, 2019 00:15
-
-
Save standinga/d75d9f7ef758c71ee64f1cb062c3241b to your computer and use it in GitHub Desktop.
IOS, Swift, Photos, gettin videos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVKit | |
import Photos | |
func getVideos() -> PHFetchResult<PHAsset> { | |
let fetchOptions = PHFetchOptions() | |
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate",ascending: false)] | |
fetchOptions.predicate = NSPredicate(format: "mediaType = %d",PHAssetMediaType.video.rawValue) | |
return PHAsset.fetchAssets(with: fetchOptions) | |
} | |
let imagesAndVideos = getVideos() | |
imagesAndVideos.enumerateObjects({ (object, count, stop) in | |
PHImageManager.default().requestAVAsset(forVideo: object, options: nil, resultHandler: { (avasset, audiomix, info) in | |
guard let avasset = avasset else { | |
fatalError("avassset nil") | |
} | |
}) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment