当您播放音乐时,在锁定屏幕上会显示音乐标题和时间。我也看到TuneIn电台是如何通过显示当前播放电台的名称来实现这一点的。您该如何做到这一点?
以下是一段可以在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;
}