【发布时间】:2018-05-23 14:39:26
【问题描述】:
我正在构建一个需要打开手电筒模式的 AR 应用。打开手电筒模式,然后启用 AR 场景在我的 iPhone 8 上运行良好,但在 iPhone X 上,手电筒打开然后再次关闭。有什么办法可以解决这个问题,或者我必须做些什么才能让 iPhone X 正常工作?
- (void)turnTorchOn:(bool) on {
Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
if (captureDeviceClass != nil) {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch]){
[device lockForConfiguration:nil];
if (on) {
[device setTorchMode:AVCaptureTorchModeOn];
} else {
[device setTorchMode:AVCaptureTorchModeOff];
}
[device unlockForConfiguration];
}
}
}
然后:
self.arConfig = [ARWorldTrackingConfiguration new];
self.arConfig.planeDetection = ARPlaneDetectionHorizontal;
self.sceneView = [[ARSCNView alloc] initWithFrame:self.view.frame];
[self.view addSubview:self.sceneView];
SCNScene *scene = [SCNScene new];
self.sceneView.scene = scene;
self.sceneView.autoenablesDefaultLighting = YES;
self.sceneView.delegate = self;
self.sceneView.session.delegate = self;
更具体地说,这条线会关闭手电筒:
self.sceneView = [[ARSCNView alloc] initWithFrame:self.view.frame];
【问题讨论】:
-
我的猜测是配置捕获会话/设备的 ARKit 会干扰您设置的内容。您是否尝试过在 AR 会话开始后而不是之前打开手电筒?
-
@rickster 是的,我尝试过切换订单,但它也失败了。奇怪的是只有 iPhone X 有这个问题。有什么其他的想法可以让我尝试吗?
-
因为这只发生在 iPhone X 上,我会和苹果一起打开雷达。
标签: ios objective-c arkit iphone-x flashlight