Objective-C:没有调用volumeChanged甚至为AVSystemController_SystemVolumeDidChangeNotification添加一个Observer? [英] Objective-C: volumeChanged wasn't called even add a Observer for AVSystemController_SystemVolumeDidChangeNotification?

查看:905
本文介绍了Objective-C:没有调用volumeChanged甚至为AVSystemController_SystemVolumeDidChangeNotification添加一个Observer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- (void)viewDidLoad {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
}

- (void)volumeChanged:(NSNotification *)notification{

    float volume = [[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
    //[self innerSetVolume:volume];
}

当我按下向上/向下硬件音量按钮时,不会调用volumeChanged设备。
之前有人遇到过这个问题吗?

volumeChanged will not be called when I push the up/down hardware volume button on device. somebody met the question before?

PS:我的测试设备是iOS 4.3的iPod touch,而不是iPhone。

PS:my test device is iPod touch with iOS 4.3, not iPhone.

推荐答案

我认为您需要启动音频会话服务才能触发这些通知。

I believe you need to start up Audio Session Services in order for those notifications to fire.

以下是该电话的文档 - http://developer.apple.com/library/ios/documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html# // apple_ref / c / func / AudioSessionSetActive

Here's the documentation for the call -- http://developer.apple.com/library/ios/documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html#//apple_ref/c/func/AudioSessionSetActive

这篇关于Objective-C:没有调用volumeChanged甚至为AVSystemController_SystemVolumeDidChangeNotification添加一个Observer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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