Objective-C Mac OS X分布式通知iTunes

Sam*_*ami 4 xcode notifications itunes objective-c scripting-bridge

我需要一点帮助,我现在有一个方法; 我的Mac OS X应用程序中的updateTrackInfo获取当前在iTunes中播放的艺术家名称,曲目名称和曲目的持续时间

但是,我希望应用程序监听分发的iTunes通知; com.apple.iTunes.playerInfo然后在iTunes分发通知时调用方法updateTrackInfo.请有人帮助我,我需要在标题和实现文件中写什么.

谢谢,萨米.

Dav*_*ong 13

您正在寻找-[NSDistributedNotificationCenter addObserver:selector:name:object:]:

NSDistributedNotificationCenter *dnc = [NSDistributedNotificationCenter defaultCenter];
[dnc addObserver:self selector:@selector(updateTrackInfo:) name:@"com.apple.iTunes.playerInfo" object:nil];
Run Code Online (Sandbox Code Playgroud)

在同一个班级的其他地方......

- (void) updateTrackInfo:(NSNotification *)notification {
  NSDictionary *information = [notification userInfo];
  NSLog(@"track information: %@", information);
}
Run Code Online (Sandbox Code Playgroud)

它甚至可以在通知中为您提供一大堆跟踪信息.不是很好吗?