MPNowPlayingInfoCenter defaultCenter不会更新或检索信息

Jay*_*ane 28 iphone mpmovieplayercontroller ios

我正在努力更新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];


    }
Run Code Online (Sandbox Code Playgroud)

这不起作用,我也尝试过:

   [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nil];
Run Code Online (Sandbox Code Playgroud)

试图让它从iPod应用程序中删除现有信息(或任何可能有信息的信息).另外,为了看看我是否能找到问题,我已经尝试检索应用启动时的当前信息:

  NSDictionary *info = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];
  NSString *title = [info valueForKey:MPMediaItemPropertyTitle];
  NSString *author = [info valueForKey:MPMediaItemPropertyArtist];

  NSLog(@"Currently playing: %@ // %@", title, author);
Run Code Online (Sandbox Code Playgroud)

我明白了 Currently playing: (null) // (null)

我对此进行了相当多的研究,以下文章对此进行了彻底的解释,但是,我仍然无法正常工作.我错过了什么吗?会有什么干扰吗?这是我的应用程序需要注册访问的服务(在任何文档中都没有看到这个)吗?

Apple的文档

更改锁定屏幕背景音频控件

现在播放信息被忽略

Jay*_*ane 55

我终于找到了问题,我没有提示我的应用程序接收远程控制事件,只需添加此行修复了问题:

 [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
Run Code Online (Sandbox Code Playgroud)