开发者

Objective-C, constantly run method whilst Mac OS X application is running

i'm currently writing an application in Objective-C which displays the artist name of the song currently being played in iTunes, however i want the artist name to update when the song changes.

This is the method i have so far which gets the artist name and sets a NSTextField to display the artist name.

 - (void)upd开发者_JAVA技巧ateArtistName {
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
     NSString *artistNameString = [NSString stringWithFormat:@"%@", [[iTunes currentTrack] artist]];
     [artistName setStringValue:artistNameString];}

Any help would be much appreciated, thanks, Sami.


What you're looking for is: NSDistributedNotificationCenter. http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Notifications/Articles/Registering.html

To figure out which notifications Itunes is sending most people suggest using: https://github.com/kballard/NotificationWatcher

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜