2

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
 }

 }
1
  • the problem was the "ph://" prefix of the local identifier i removed it and it gets the phasset now but i dont know how to convert it into a filename,type,uri object so javascript can read it Commented Aug 18, 2020 at 20:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.