У меня есть собственное представление, использующее 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]
Кажется, все установлено, как вы сказали, не могли бы вы описать, как убедиться, что NSLayoutConstraints в этом случае в порядке?
Чтобы быть уверенным, я установил красный цвет ARSceneView, и представление, кажется, отображается правильно. Я также попытался изменить свой пользовательский вид на ARSCNView по умолчанию, и он также не работает.
обновил, как вы сказали, и все равно не работает. Я добавлю вывод Xcode к моему вопросу, может быть, это поможет
В меню Xcode выберите
Product > Scheme > Edit Scheme
и установите для переменной средыOS_ACTIVITY_MODE
значениеdisable
. Затем посмотрите, что печатает консоль.