在控制中心显示 Spotify 正在播放的项目信息

Display Spotify now playing item info in Control Center

我在 iOS 应用程序中使用新的 Spotify SDK。在此我使用下面的代码播放来自 Spotify.I 的歌曲我能够播放这首歌。但是我无法看到正在播放的项目歌曲信息,也无法从 iOS 控制中心控制歌曲。我需要将歌曲信息更新到控制中心。

[SPTTrack trackWithURI:appDelegate.player.currentTrackURI
               session:auth.session
              callback:^(NSError *error, SPTTrack *track) {

                  self.trackTitle.text = track.name;

                  SPTPartialArtist *artist = [track.artists objectAtIndex:0];
                  self.trackArtist.text = artist.name;

                  appDelegate.currentPlayingSongName = track.name;
                  appDelegate.currentPlayingArtistName = artist.name;

                  //[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = [NSDictionary dictionaryWithObject:track.name forKey: MPMediaItemPropertyTitle];

                  Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

                  if (playingInfoCenter) {

                      NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];

                      [songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle];
                      [songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist];
                      [songInfo setObject:@"Audio Album" forKey:MPMediaItemPropertyAlbumTitle];
                      [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];


                  }

}]; 

感谢您阅读我的问题。提前致谢

我昨天在寻找相同的信息时找到了您的 post。从那时起我就明白了。但这是在 swift 中。我刚刚开始学习 xcode 和 swift。所以不知道如何在 objc 中翻译它。希望这会有所帮助 ;)

//show now playing info:

var player: SPTAudioStreamingController?
let songInfo = [
                MPMediaItemPropertyTitle:  self.player!.currentTrackMetadata[SPTAudioStreamingMetadataTrackName] as! String,
                MPMediaItemPropertyArtist: self.player!.currentTrackMetadata[SPTAudioStreamingMetadataArtistName] as! String,
                MPMediaItemPropertyArtwork: albumArt,
                MPNowPlayingInfoPropertyElapsedPlaybackTime: self.player!.currentPlaybackPosition,
                MPMediaItemPropertyPlaybackDuration: self.player!.currentTrackDuration,
                MPNowPlayingInfoPropertyPlaybackRate:  1.0
            ]
            MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = songInfo


//setup and receive remote control events:

UIApplication.sharedApplication().beginReceivingRemoteControlEvents()

// then 

override func remoteControlReceivedWithEvent(event: UIEvent?) {
    if event!.type == UIEventType.RemoteControl {
        if event!.subtype == UIEventSubtype.RemoteControlPlay {
            togglePlay()
//etc...