당신은 -[NSDistributedNotificationCenter addObserver:selector:name:object:]
찾고 : 다른 곳에서 같은 클래스에서
NSDistributedNotificationCenter *dnc = [NSDistributedNotificationCenter defaultCenter];
[dnc addObserver:self selector:@selector(updateTrackInfo:) name:@"com.apple.iTunes.playerInfo" object:nil];
... 그것은 심지어 당신에게 통지 트랙 정보의 전체 무리를 제공
- (void) updateTrackInfo:(NSNotification *)notification {
NSDictionary *information = [notification userInfo];
NSLog(@"track information: %@", information);
}
합니다. 멋지지 않아?
- (id) init {
self = [super init];
if (!self) return nil;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveNotification:)
name:@"com.apple.iTunes.playerInfo"
object:nil];
return self;}
- (void) receiveNotification:(NSNotification *) notification {
if ([@"com.apple.iTunes.playerInfo" isEqualToString:@"com.apple.iTunes.playerInfo"]) {
NSLog (@"Successfully received the test notification!");
}}
을하지만 NSNotificationCenter 대신 NSDistributedNotificationCenter를 사용 : 당신의 도움에 대한
대단히 효과적이지만 현재 노래가 멈췄을 때 알려주지 않습니다. 즉 현재 노래가 _no_입니다. – seaturtle