我有一个使用darwin通知中心的应用。
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
displayStatusChanged, // callback
CFSTR("com.apple.iokit.hid.displayStatus"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
我真的想在后台捕捉音量按钮按下。我发现列出了这些通知
http://iphonedevwiki.net/index.php/SpringBoard.app/Notifications
有没有办法在SBMediaVolumeChangedNotification上触发方法?
答案 0 :(得分:0)
SBMediaVolumeChangedNotification不是Darwin通知,它是默认的本地通知。要捕获它,你需要一个通用的通知观察器,就像这个(在Swift中):
NSNotificationCenter.defaultCenter().addObserver(self, selector: "volumeChanged:", name: "SBMediaVolumeChangedNotification", object: nil)
但是,文档说明:
该对象是SBMediaController实例。
所以我认为我们需要将SBMediaController实例作为对象传递给观察者,以使其工作。由于似乎无法从SDK中访问SBMediaController类,因此我认为没有办法使用该特定通知。我试过没有这个对象,但它对我没用。