2

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

Community
  • 1
  • 1
Hyder
  • 1,163
  • 2
  • 13
  • 37

1 Answers1

0

I am facing the same issue right now. What I was able to find out is that Apple will reject your app if it alters some basic hardware functionalities. See this link: https://developer.apple.com/app-store/review/guidelines/. On the other hand it is misleading since there are many camera apps on App Store, like Snapchat, that clearly use volume buttons / long press for other purposes.

Anyways, I managed to handle long press, see this thread: https://github.com/jpsim/JPSVolumeButtonHandler/issues/27#issuecomment-253979943

Timo
  • 41
  • 5
  • ahh, those Snapchat - rule breakers! – Mr.Fingers Oct 17 '16 at 15:06
  • Yes, we also implemented such feature, but with dispatch_after() method. Its my personal whining, because we make Snapchat like App . Need to collect voices for Snapchat ban on appstore) – Mr.Fingers Oct 19 '16 at 11:35
  • I see, have you tried to submit your app to App Store? Just curious if really gets rejected. – Timo Oct 19 '16 at 12:29