How to implement a volume key shutter for iPhone?

后端 未结 5 818
[愿得一人]
[愿得一人] 2020-12-07 23:24

I want to implement the same behavior with the native camera of iOS5:

  • press the volume + button to take a photo

What\'s the

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 00:03

    There's currently no official way to capture the volume key pressed event. Apple's stated line is that the volume button works with the UIImagePickerController if you've allowed it to show camera controls.

    Other approaches, such as listening for the notification, seem to be unsupported hacks that Apple's team are — anecdotally — sometimes turning a blind eye to. To prevent the volume HUD from appearing you can use the undocumented UIApplication methods:

    - (void)setSystemVolumeHUDEnabled:(BOOL)enabled;
    - (void)setSystemVolumeHUDEnabled:(BOOL)enabled forAudioCategory:(NSString *)category;
    

    The only statement of their use I've seen is:

    UIApplication *app = [UIApplication sharedApplication];
    [app setSystemVolumeHUDEnabled:NO forAudioCategory:@"Ringtone"];
    [app setSystemVolumeHUDEnabled:NO];
    

    I'm unsure if or why you seemingly need to disable the HUD for a specific category and then in general, but without proper documentation that's difficult to figure out.

    So: use UIImagePickerController and its camera buttons if you want to be within the rules. If you've found an app that seems to work outside of the rules then it's probably using the methods above.

提交回复
热议问题