程序访问iPhone音量按钮 [英] program access to iPhone volume buttons

查看:83
本文介绍了程序访问iPhone音量按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法订阅音量按钮按事件?

Is there any way to subscribe to volume buttons press events?

推荐答案

最近苹果拒绝后

请勿使用此功能。 Apple现在使用一些补丁,如果它使用任何私有API,它会立即拒绝你的应用程序 - 虽然应该注意到App Store上的一些应用程序已经使用它并且仍在那里!

Do not use this. Apple now uses some patch which would reject your app straightaway if it uses any of the private APIs - though should note here that quite some apps on the App Store use this already and are still there!

现在唯一的方法就是让AVAudioPlayer准备播放但不播放([player prepareToPlay])。这似乎可以根据摇杆按钮调整应用程序的音量。

The only way to do this now is to have an AVAudioPlayer prepared to play but not playing ([player prepareToPlay]). This seems to take care of adjusting the app's volume according to the rocker buttons.

目前还没有其他方法可以解决这个问题。

There's no other published way currently to handle this.

请阅读上述注释

是,使用MPVolumeView

Yes, Use the MPVolumeView

MPVolumeView *volume = [[[MPVolumeView alloc] initWithFrame:CGRectMake(18.0, 340.0, 284.0, 23.0)] autorelease];
  [[self view] addSubview:volume];

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) 
                                        name:@"AVSystemController_SystemVolumeDidChangeNotification" 
                                        object:nil];    
  for (UIView *view in [volume subviews]){
    if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
      volumeViewSlider = view;  //volumeViewSlider is a UIView * object
    }
  }
  [volumeViewSlider _updateVolumeFromAVSystemController];

-(IBAction)volumeChanged:(id)sender{
  [volumeViewSlider _updateVolumeFromAVSystemController];
}

这将为您提供一个滑块(与ipod中使用的滑块相同)的值将改变手机的音量

This will give you a slider (same as one used in ipod) whose value will change acc to volume of the phone

您将收到一个编译时警告,视图可能无法响应_updateVolumeFromAVSystemControl,但只是忽略它。

You will get a compile-time warning that view may not respond to _updateVolumeFromAVSystemControl, but just ignore it.

这篇关于程序访问iPhone音量按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆