我正在尝试构建一个自定义图像库,用户可以从中选择多个图像并通过FormData上载,但是在iOS上从CameraRoll库获取ph:// SOMETEXT kinda uri,它是“ LocalIdentifier”,对此进行了描述问题https://github.com/react-native-community/react-native-cameraroll/issues/195#issuecomment-655549166,而我正在尝试搭建一个快速桥梁以实现该功能,因为该功能可以在他解释时返回图像的真实uri,但是当我尝试
let photo = PHAsset.fetchAssets(withLocalIdentifiers:
['localUriGotFromReactNativeCameraRool'], options: .none).firstObject
在我的函数中,它总是返回没有实际图像的空对象
这是我的完整代码
import Foundation
import Photos
@objc(RNFetchAssets)
class RNFetchAssets: NSObject {
@objc
func fetch(
_ localUri: String,
resolve: RCTPromiseResolveBlock,
rejecter reject: RCTPromiseRejectBlock
) -> Void {
let requestOptions = PHImageRequestOptions()
requestOptions.isSynchronous = false
let photo = PHAsset.fetchAssets(withLocalIdentifiers: [localUri], options: .none).firstObject
print(photo ?? "None");
//resolve(photo)
}
private func fetchOptions() -> PHFetchOptions {
let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
return fetchOptions
}
@objc
static func requiresMainQueueSetup() -> Bool {
return true
}
}