如何在iPhonelocking屏幕上设置当前播放audio的标题?

当您播放音乐时,音乐标题将显示在locking屏幕的下方。

我也看到了TuneIn收音机是如何通过显示当前正在播放的电台名称来实现的。

你是怎样做的?

阅读文档: MPNowPlayingInfoCenter

这里是一个示例代码,将在iOS 5上工作,它不会在旧版本的iOS上崩溃。

 Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter"); if (playingInfoCenter) { MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter]; NSDictionary *songInfo = [NSDictionary dictionaryWithObjectsAndKeys: @"Some artist", MPMediaItemPropertyArtist, @"Some title", MPMediaItemPropertyTitle, @"Some Album", MPMediaItemPropertyAlbumTitle, nil]; center.nowPlayingInfo = songInfo; }