反应本机CameraRoll文件上传

时间:2020-08-18 16:03:29

标签: swift react-native react-native-ios react-native-native-module

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

 }

0 个答案:

没有答案