小编Abr*_*ras的帖子

在后台模式下使用App接收通知

我有一个应用程序,可以跟踪用户在iPod应用程序中执行的所有操作.为此,我向NSNotificationCenter添加了一些观察者,如MPMusicPlayerControllerNowPlayingItemDidChangeNotification.但我的问题是,当我的应用程序在前台时,我只收到这些通知,如果它在后台,系统将通知添加到队列,然后下次我的应用程序变为活动状态时,它会将它传递给我.我对这个队列没兴趣,因为我想收到实时通知.

即使我的应用程序处于挂起状态,有没有办法让我收到这些通知?我想每次运行NowPlayingItemDidChange通知时只运行3行代码.

这是我添加观察者的地方.

MPMusicPlayerController *iPodMediaPlayer = [MPMusicPlayerController iPodMusicPlayer];



NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

     [notificationCenter addObserver: self selector: @selector(handle_NowPlayingItemChanged:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification

                                    object:iPodMediaPlayer];


 [iPodMediaPlayer beginGeneratingPlaybackNotifications];
Run Code Online (Sandbox Code Playgroud)

此外,如果我向观察者而不是iPodMediaPlayer添加另一种对象,观察者将不会调用该方法.

非常感谢,

阿巴拉

iphone notifications background ipod ios

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

background ×1

ios ×1

iphone ×1

ipod ×1

notifications ×1