title: Detect long and short press of volume button - iOS
body: <p>I have been looking around like crazies. I need to do custom actions on volume button long and short press (like snapchat, short press take picture, long press record video) but have failed.</p>
  
  <p>I have used <a href="https://github.com/jpsim/JPSVolumeButtonHandler" rel="nofollow noreferrer">https://github.com/jpsim/JPSVolumeButtonHandler</a> 
   which has allowed me to detect the volume button press event. but after trying very hard I have failed to detect when its a long press and when its a short press.</p>
  
  <p>also refer to <a href="https://stackoverflow.com/questions/28228243/detect-iphone-volume-button-hold-ios-8">Detect iPhone Volume Button Hold? (iOS 8)</a></p>
  
  <p>my code</p>
  
  <pre><code>//Volume button handler
  
  self.volumeButtonHandler = [JPSVolumeButtonHandler volumeButtonHandlerWithUpBlock:^{
          // Volume Up Button Pressed
          [self onVolumeUp];
      } downBlock:^{
          // Volume Down Button Pressed
      }];
  
  -(void)onVolumeUp {
      if(self.volButtonTimer) {
          secondsElapsed = 1; //To detect long press
          [self.volButtonTimer invalidate];
      }
      self.volButtonTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
                                                    target:self
                                                  selector:@selector(onTimerFire)
                                                  userInfo:nil
                                                   repeats:NO];
  
  }
  
  -(void)onTimerFire {
      NSLog(@"Long Press %d",secondsElapsed);
      if (secondsElapsed &gt; 1)
      {
          //Do Something
      }
      else secondsElapsed = 0;
  
  }
  </code></pre>
  
  <p>Please I need help on this. Searched all over google but failed. If snapchat is doing it, means its doable. </p>
  
  <p>Thank you</p>