jpsim / JPSVolumeButtonHandler

JPSVolumeButtonHandler provides an easy block interface to hardware volume buttons on iOS devices. Perfect for camera apps!
MIT License
333 stars 90 forks source link

Is there more to getting this working than the readme says? #17

Open dtirer opened 8 years ago

dtirer commented 8 years ago

I'm just doing a quick test prototype to make sure that I can in fact respond to volume buttons presses. I installed VolumeButtonHandler via Cocoapods, ensured that my project sees it and implemented the following as a test in ViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

    self.outputLabel.text = @"";

    self.volumeHandler = [JPSVolumeButtonHandler volumeButtonHandlerWithUpBlock:^{
        self.outputLabel.text = @"  Up!  ";
    } downBlock:^{
        self.outputLabel.text = [self.outputLabel.text stringByAppendingString:@"  Down!  "];
    }];
}

When I load it up on my iPhone6, It doesn't print anything to my label upon pressing vol up or down

X140Yu commented 7 years ago

Me too, don't know what's going on here

creitz commented 7 years ago

I had the same issue a while ago and found that you need to call: [self.volumeHandler start]; after you initialize the volumeHandler. (I'm doing it in swift, so I'm guessing about the method signature for Obj-C). You should also do: [self.volumeHandler stop]; self.volumeHandler = nil; in something like the viewDidDisappear() or similar, depending on your usage.