2011-05-01 89 views
3

我知道您可以使用[iTunesDNC addObserver:self selector:@selector(updateInfo:) name:@"com.apple.iTunes.playerInfo" object:nil];每次播放器更改歌曲/停止/播放等时收到通知。但我需要的是每次在iTunes上更改信息时的通知(例如,歌曲标题更改,歌词更改,艺术家等)使用NSDistributedNotificationCenter获取iTunes上的歌曲信息更改通知

有什么建议吗?林相当确定我只需要更改com.apple.iTunes.playerInfo其他不是playerInfo

我知道它应该是可行的,因为有一个名为SongGenie的应用程序,如果您在iTunes上编辑歌曲的ID3标签或添加歌词,它将更改其信息。

谢谢!

回答

11

是的,有一种方法。每当歌曲信息被更改时,iTunes会发布一条“com.apple.iTunes.sourceSaved”通知,其userInfo词典是用户的库。

您可以通过收听发送到分布式通知中心的每个通知,查看iTunes发送的此通知和其他通知。

[[NSDistributedNotificationCenter defaultCenter] addObserver:self 
                selector:@selector(allDistributedNotifications:) 
                name:nil 
                object:nil]; 

- (void) allDistributedNotifications:(NSNotification *)note 
{ 
    NSString *object = [note object]; 
    NSString *name = [note name]; 
    NSDictionary *userInfo = [note userInfo]; 
    NSLog(@"<%p>%s: object: %@ name: %@ userInfo: %@", self, __PRETTY_FUNCTION__, object, name, userInfo); 
} 
+0

哥们,你太棒了谢谢!哈哈不仅通过iTunes歌曲改变(我几乎放弃了)而保存了我的理智,而且还检查了所有通知的功能......哈哈哈我想知道是否有类似的东西!谢谢! – 2011-05-01 22:07:30

+1

这不是给你所有应用程序的通知,而不仅仅是iTunes吗? – 2011-12-13 20:43:26

+0

是的,如果应用程序向NSDistributedNotificationCenter发送通知,它确实会给你。 – mohacs 2014-05-27 23:18:21

相关问题