每当我播放一首曲子,然后转到后台,我就无法在我的应用程序中触发这些通知。有人知道为什么或者是怎么回事吗?
self.player = [MPMusicPlayerController applicationMusicPlayer];
[self.player beginGeneratingPlaybackNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePlaybackStateChanged:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:self.player ];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleItemChanged:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification object:self.player ];发布于 2016-08-31 00:11:57
添加以下代码
UIBackgroundTaskIdentifier bgTask = 0;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];在AppDelegate的applicationDidEnterBackground方法中,您的方法也将在AppDelegate中工作。
还可以启用
音频、播放和画中画
来自功能。查看屏幕截图

https://stackoverflow.com/questions/39231708
复制相似问题