如何从库中获取所有照片

Vin*_*nan 5 photos ios swift

下面显示的代码就是我已经尝试过的.我希望实现的是从设备中获取所有照片.目前只有少数被提取.如何修改代码以便从设备加载所有图像?

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
}
Run Code Online (Sandbox Code Playgroud)

Cod*_*der 19

更新了David对iOS 10+和Swift 4.x/3.x的回答:

请求设备访问照片的权限:

将以下值添加到您的 info.plist

隐私 - 照片库使用说明

并提供向用户显示的字符串.

请求所有图片:

PHPhotoLibrary.requestAuthorization { status in
    switch status {
    case .authorized:
        let fetchOptions = PHFetchOptions()
        let allPhotos = PHAsset.fetchAssets(with: .image, options: fetchOptions)
        print("Found \(allPhotos.count) assets")
    case .denied, .restricted:
        print("Not allowed")
    case .notDetermined:
        // Should not see this when requesting
        print("Not determined yet")
    }
}
Run Code Online (Sandbox Code Playgroud)