我有一个使用ARSCNView的自定义视图,假设它是这样的
import Foundation
import UIKit
import ARKit
import SceneKit
@available(iOS 11.0, *)
class ARSceneView: ARSCNView, ARSessionDelegate, ARSCNViewDelegate {
}我需要在React Native中使用它,所以我创建了快速视图管理器:
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]发布于 2021-08-09 03:46:53
在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>另外,我希望view的NSLayoutConstraints是OK的。
并确保您没有忘记提供一个场景插槽:
sceneView.scene = SCNScene() https://stackoverflow.com/questions/68704350
复制相似问题