我正在更新MPNowPlayingInfoCenter,遇到了一些问题。我已经尝试了很多方法,但是现在感到困惑。以下是我的代码:
self.audioPlayer.allowsAirPlay = NO;
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"series_placeholder"]];
[songInfo setObject:thePodcast.title forKey:MPMediaItemPropertyTitle];
[songInfo setObject:thePodcast.author forKey:MPMediaItemPropertyArtist];
[songInfo setObject:@"NCC" forKey:MPMediaItemPropertyAlbumTitle];
[songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
}
这个方法不起作用,我也尝试过:
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nil];
我试图让它从iPod应用程序(或可能在那里有信息的任何应用程序)中删除现有信息。此外,只是为了查找问题,我已经尝试在应用程序启动时检索当前信息:
NSDictionary *info = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];
NSString *title = [info valueForKey:MPMediaItemPropertyTitle];
NSString *author = [info valueForKey:MPMediaItemPropertyArtist];
NSLog(@"Currently playing: %@ // %@", title, author);
我得到了Currently playing: (null) // (null)
的结果。
我已经做了很多研究,以下几篇文章对此进行了详细的解释,但是我仍然无法使其正常工作。我是否漏掉了什么?是否有任何干扰因素?这是我的应用程序需要注册才能访问的服务吗(在任何文档中都没有看到)?