0 Replies
      Latest reply on May 23, 2018 11:21 AM by wannasoda321
      wannasoda321 Level 1 Level 1 (0 points)

        I am building an AR app that needs the flashlight to be turned on torch mode. Turning on torch mode and then enabling the AR scene works fine on my iPhone 8, but on the iPhone X, it the flashlight turns on and then off again. Is there some way around this, or something specific I have to do for the iPhone X to work?

         

        - (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];
                }
            }
        }

         

        And then later:

         

        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;

         

        More specifically, this is the troublesome line that turns off the flashlight.

        self.sceneView = [[ARSCNView alloc] initWithFrame:self.view.frame];

        Switching the order of these actions doesn't make a difference unfortuantly. Any ideas?