原生应用程序中的iOS自定义耳机按钮控制器

时间:2016-03-03 20:19:57

标签: ios objective-c iphone xcode ipad

我还为应用程序开发了功能,我想使用按键耳机。使用音量调高和音量调低按钮更改耳机中的菜单,我希望使用MUTE按钮进行菜单选择。关于这个活动可以帮到我吗?

注意:SDK 7和7 +

感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码获取音量/静音级别,这对我有用:

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[NSNotificationCenter defaultCenter]
    addObserver:self
    selector:@selector(volumeChanged:)
    name:@"AVSystemController_SystemVolumeDidChangeNotification"
    object:nil];
}

- (void)volumeChanged:(NSNotification *)notification
{
    float volume =
    [[[notification userInfo]
      objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]
 floatValue];

// Do stuff with volume
}