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.
I have used https://github.com/jpsim/JPSVolumeButtonHandler 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.
also refer to Detect iPhone Volume Button Hold? (iOS 8)
my 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 > 1)
{
//Do Something
}
else secondsElapsed = 0;
}
Please I need help on this. Searched all over google but failed. If snapchat is doing it, means its doable.
Thank you