我正在尝试构建一个自定义图像库,用户可以从中选择多个图像并通过 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
}
}