Get an error when trying to get all the photos from PHAssetCollection.fetchAssetCollections

自闭症网瘾萝莉.ら 提交于 2020-08-01 09:23:08

问题


I want to get all the photos of my custom album. but instead what I get is the below error.

My Code

let collections:PHFetchResult = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: fetchOptions)

Error i get

"Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)""

Any ideas on how to fix this?


回答1:


Based on the comments, I'm not entirely sure what the issue is but I hope this code could provide some assistance. Using .album rather than .smartAlbum could also be part of the issue.

private var fetchResult: PHFetchResult<PHAsset>!

func fetchOptions(_ predicate: NSPredicate?) -> PHFetchOptions {
            let options = PHFetchOptions()
            options.sortDescriptors = [ NSSortDescriptor(key: "creationDate", ascending: false) ]
        options.predicate = predicate
        return options
    }
}

    if let userLibraryCollection = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumUserLibrary, options: nil).firstObject {
        self.fetchResult = PHAsset.fetchAssets(in: userLibraryCollection, options: fetchOptions(NSPredicate(format: "mediaType = \(PHAssetMediaType.image.rawValue)")))
    } else {
        self.fetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions(nil))
    }


来源:https://stackoverflow.com/questions/57803075/get-an-error-when-trying-to-get-all-the-photos-from-phassetcollection-fetchasset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!