title: Stop flashlight ios
body: <p>I have a flashlight app . 
  I use this for making flash :</p>
  
  <pre><code>NSTimer * myTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 
                                                       target:self 
                                                     selector:@selector(toggleFlashlight) 
                                                     userInfo:nil 
                                                      repeats:YES];`
  - (void)toggleFlashlight{
  
  
      Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
      if (captureDeviceClass != nil) {
          AVCaptureDevice *device = 
           [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
          if ([device hasTorch] &amp;&amp; [device hasFlash]){
  
              [device lockForConfiguration:nil];
              if (device.torchMode == AVCaptureTorchModeOff) {
                  [device setTorchMode:AVCaptureTorchModeOn];
                  [device setFlashMode:AVCaptureFlashModeOn];
                  //torchIsOn = YES;
              } else {
                  [device setTorchMode:AVCaptureTorchModeOff];
                  [device setFlashMode:AVCaptureFlashModeOff];
                  // torchIsOn = NO;
              }
  
          [device unlockForConfiguration];
          }
      }    
  }
  </code></pre>
  
  <p>but i want to stop it when i press a button . How can i do that? It's working to stop the light it if i dont have flash.</p>