I am trying to build a custom image gallery that user can select multiple images from it and upload by FormData but on iOS from CameraRoll library it gets ph://SOMETEXT kinda uri which is a "LocalIdentifier" and its described on this issue https://github.com/react-native-community/react-native-cameraroll/issues/195#issuecomment-655549166 and i am trying make a swift bridge to implement that function can return a real uri of the image as he is explaining but when I try
let photo = PHAsset.fetchAssets(withLocalIdentifiers:
['localUriGotFromReactNativeCameraRool'], options: .none).firstObject
in my function it always returns empty object without the actual image
this is my full code
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
}
}