RCTPresentedViewController 不打开 UIImagePickerController

问题描述 投票:0回答:0

我正在尝试使用

react native's new architecture
UIImagePickerController
iOS

打开相机应用程序

我已经在

swift
中编写了代码,我正在通过
objective-c

调用它

这是我的

objective-c++
代码

#import <Foundation/Foundation.h>
#import "RTNMyCamera.h"
#import "myapp-Swift.h"

@implementation RTNMyCamera
RCT_EXPORT_MODULE()

MyCamera *myCamera = [[MyCamera alloc] init];

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
    (const facebook::react::ObjCTurboModule::InitParams &)params
{
    return std::make_shared<facebook::react::NativeMyCameraSpecJSI>(params);
}

- (void)takePhoto {
  [myCamera takePhotoFromCamera];
}

@end

我的

swift
文件中的下一个

import Foundation
import Photos
import React
 
@objcMembers class MyCamera: NSObject,UINavigationControllerDelegate,UIImagePickerControllerDelegate {
  
  let presentedViewController = RCTPresentedViewController()
  let viewController = UIApplication.shared.windows.first?.rootViewController

  func takePhotoFromCamera() {
    DispatchQueue.main.async {
      debugPrint("1")
      let vc = UIImagePickerController()
      vc.sourceType = .camera
      vc.allowsEditing = true
      debugPrint("2")
      vc.delegate = self
      self.viewController?.present(vc, animated: true)
      debugPrint("3")
    }
//    present(vc, animated: true)
  }
  
  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    debugPrint("4")
    picker.dismiss(animated: true)
    debugPrint("5")
    guard let image = info[.editedImage] as? UIImage else {
 .........

我尝试使用

self.presentedViewController?.present(vc, animated: true)
self.viewController?.present(vc, animated: true)
,似乎没有任何效果,我也没有在日志中收到错误消息

完整源代码在这里

ios swift react-native objective-c++ ios-camera
© www.soinside.com 2019 - 2024. All rights reserved.