2011-05-01 91 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

相關問題