The code shown below is what i've tried already.What I wish to achieve is to fetch all the photos from the device.Currently only a few are being fetched.How to modify the code so as to load all the images from device?
let fetchOptions = PHFetchOptions()
let collection:PHFetchResult = PHAssetCollection.fetchAssetCollectionsWithType(.Moment, subtype: .Any, options: fetchOptions)
if let first_Obj:AnyObject = collection.firstObject
{
self.assetCollection = first_Obj as! PHAssetCollection
}
Updated David's answer for iOS 10+ & Swift 4.x/3.x:
Request permission from the device to access photos:
Add the following value to your
info.plist
And provide a string that is shown to the user.
Request all images:
All photos is pretty easy, but you need to ensure that you're authorized first. Here's some simple code to demonstrate:
On my phone this returns 25750 items. On a fresh simulator, this should yield 5 images.