启用AR Camera时,iPhone X手电筒关闭

我正在构建一个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];