I'm trying to get the asset resources for a PHAsset and am having a little trouble. I'm able to fetch the PHAsset with no problems, yet the resources for the asset is always empty. This is not happening with every photo, but one in particular has been giving me troubles. Curious if there's something I'm missing and this is expected behaviour in certain contexts.
let options = PHFetchOptions()
options.includeAssetSourceTypes = [.typeCloudShared, .typeUserLibrary, .typeiTunesSynced]
options.includeHiddenAssets = true
let identifier = ...
if let asset = PHAsset.fetchAssets(withLocalIdentifiers: [identifier], options: options).firstObject {
let resources = PHAssetResource.assetResources(for: asset)
print(resources.count) // 0
}
Realized that the imageData was null because I didn't set isNetworkAccessAllowed to true. After doing that I have a new issue.
let imageOptions = PHImageRequestOptions()
imageOptions.isNetworkAccessAllowed = true
PHImageManager.default().requestImageData(for: asset, options: imageOptions) { (imageData, dataUTI, orientation, info) in
print(String(describing: info)) // never called
}
// Also tried
PHImageManager.default().requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode: .default, options: imageOptions) { (image, info) in
print(String(describing: info)) // never called
}