外部 ARSCNView 以响应本机

Extern ARSCNView to react native

我有一个使用 ARSCNView 的自定义视图,假设它类似于

import Foundation
import UIKit
import ARKit
import SceneKit

@available(iOS 11.0, *)
class ARSceneView: ARSCNView, ARSessionDelegate, ARSCNViewDelegate {

}

我需要在 React Native 中使用它,所以我创建了 swift 视图管理器:

import UIKit

@objc(ARSceneViewManager)
class ARSceneViewManager : RCTViewManager {
  override func view() -> UIView! {
    if #available(iOS 11.0, *) {
      return ARSceneView(frame: .zero)
    } else {
      return UIView()
    };
 }

  override static func requiresMainQueueSetup() -> Bool {
      return true
    }
}

和 ObjC 文件:

#import "React/RCTBridgeModule.h"
#import "React/RCTViewManager.h"

@interface RCT_EXTERN_MODULE(ARSceneViewManager, RCTViewManager)

@end

我在我的 App.js 文件中使用了它:

const ARSceneView = requireNativeComponent('ARSceneView', ARSceneView);

但它似乎没有出现在屏幕上 - 我只能看到黑屏。我究竟做错了什么?如果我使用例如UILabel 而不是,一切都很好。

这是Xcode输出:

2021-08-11 11:42:51.521528+0200 ARScreen[22000:1674182] [connection] nw_endpoint_handler_set_adaptive_read_handler [C1 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for read_timeout failed
2021-08-11 11:42:51.521615+0200 ARScreen[22000:1674182] [connection] nw_endpoint_handler_set_adaptive_write_handler [C1 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for write_timeout failed
2021-08-11 11:42:51.586421+0200 ARScreen[22000:1674025] [native] Running application ARScreen ({
    initialProps =     {
    };
    rootTag = 1;
})
2021-08-11 11:42:51.598740+0200 ARScreen[22000:1674182] [connection] nw_endpoint_handler_set_adaptive_read_handler [C2 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for read_timeout failed
2021-08-11 11:42:51.598819+0200 ARScreen[22000:1674182] [connection] nw_endpoint_handler_set_adaptive_write_handler [C2 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for write_timeout failed
2021-08-11 11:42:51.661793+0200 ARScreen[22000:1674183] [connection] nw_endpoint_handler_set_adaptive_read_handler [C3 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for read_timeout failed
2021-08-11 11:42:51.668304+0200 ARScreen[22000:1674183] [connection] nw_endpoint_handler_set_adaptive_write_handler [C3 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for write_timeout failed
2021-08-11 11:42:51.670879+0200 ARScreen[22000:1674183] [connection] nw_endpoint_handler_set_adaptive_read_handler [C4 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for read_timeout failed
2021-08-11 11:42:51.671031+0200 ARScreen[22000:1674183] [connection] nw_endpoint_handler_set_adaptive_write_handler [C4 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for write_timeout failed
2021-08-11 11:42:52.878308+0200 ARScreen[22000:1674193] [javascript] Running "ARScreen" with {"rootTag":1,"initialProps":{}}
2021-08-11 11:42:52.918248+0200 ARScreen[22000:1674025] Metal GPU Frame Capture Enabled
2021-08-11 11:42:52.918608+0200 ARScreen[22000:1674025] Metal API Validation Enabled
2021-08-11 11:42:53.123875+0200 ARScreen[22000:1674180] [connection] nw_endpoint_handler_set_adaptive_read_handler [C6 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for read_timeout failed
2021-08-11 11:42:53.123972+0200 ARScreen[22000:1674180] [connection] nw_endpoint_handler_set_adaptive_write_handler [C6 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for write_timeout failed
2021-08-11 11:42:54.571761+0200 ARScreen[22000:1674197] [connection] nw_socket_handle_socket_event [C5:1] Socket SO_ERROR [61: Connection refused]
2021-08-11 11:42:54.573292+0200 ARScreen[22000:1674180] [connection] nw_connection_get_connected_socket [C5] Client called nw_connection_get_connected_socket on unconnected nw_connection
2021-08-11 11:42:54.573526+0200 ARScreen[22000:1674180] TCP Conn 0x2805548f0 Failed : error 0:61 [61]

info.plist 文件中检查您是否有 RequiredDeviceCapabilities 个标签:

<key> UIRequiredDeviceCapabilities </key>
    <array>
        <string> armv7 </string>
        <string> arkit </string>
    </array>

Privacy–CameraUsageDescription选项:

<key> NSCameraUsageDescription </key>
    <string> This app needs your camera </string>

我也希望视图 没问题。

并确保您没有忘记输入场景槽:

sceneView.scene = SCNScene()