Objective-C Mac OS X 分布式通知 iTunes [英] Objective-C Mac OS X Distributed notifications iTunes
问题描述
我需要一点帮助,我目前有一个方法;我的 Mac OS X 应用程序中的 updateTrackInfo 获取艺术家姓名、曲目名称和当前在 iTunes 中播放的曲目的持续时间
i need a little help, i currently have a method; updateTrackInfo in my Mac OS X application which gets the artist name, the track name and duration of the track currently being played in iTunes
但是我希望应用程序侦听分发的 iTunes 通知;com.apple.iTunes.playerInfo 然后在 iTunes 分发通知时调用方法 updateTrackInfo.请有人帮助我,我需要在头文件和实现文件中写什么.
However i want the app to listen for the distributed iTunes notification; com.apple.iTunes.playerInfo then call the method updateTrackInfo when ever the notification is distributed by iTunes. Please could someone help me, on what i would need to write in both the header and implementation file.
谢谢,萨米.
推荐答案
您正在寻找 -[NSDistributedNotificationCenter addObserver:selector:name:object:]
:
You're looking for -[NSDistributedNotificationCenter addObserver:selector:name:object:]
:
NSDistributedNotificationCenter *dnc = [NSDistributedNotificationCenter defaultCenter];
[dnc addObserver:self selector:@selector(updateTrackInfo:) name:@"com.apple.iTunes.playerInfo" object:nil];
在同一个班级的其他地方...
Elsewhere in the same class...
- (void) updateTrackInfo:(NSNotification *)notification {
NSDictionary *information = [notification userInfo];
NSLog(@"track information: %@", information);
}
它甚至会在通知中为您提供一大堆曲目信息.这不是很好吗?
It even gives you a whole bunch of track information in the notification. Isn't that nice?
这篇关于Objective-C Mac OS X 分布式通知 iTunes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!