我有一个应用程序,它将跟踪用户在iPod应用程序中做的所有事情。为此,我向NSNotificationCenter添加了一些观察者,例如MPMusicPlayerControllerNowPlayingItemDidChangeNotification。但是我的问题是,只有当我的应用程序在前台时,我才会收到这些通知,如果它在后台,则系统会将通知添加到队列中,然后在下次我的应用程序变为活动状态时将其传递给我。我对这个队列没有兴趣,因为我想收到实时通知。
是否有任何方法可以让我即使在挂起状态下也能收到这些通知?例如,每次我收到NowPlayingItemDidChange通知时运行3行代码。
这是我添加观察者的地方。
是否有任何方法可以让我即使在挂起状态下也能收到这些通知?例如,每次我收到NowPlayingItemDidChange通知时运行3行代码。
这是我添加观察者的地方。
MPMusicPlayerController *iPodMediaPlayer = [MPMusicPlayerController iPodMusicPlayer];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver: self selector: @selector(handle_NowPlayingItemChanged:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification
object:iPodMediaPlayer];
[iPodMediaPlayer beginGeneratingPlaybackNotifications];
此外,如果我向观察者添加另一种对象而不是iPodMediaPlayer,则观察者将不会调用该方法。
非常感谢,
Abras