播放音乐时,音乐标题将显示在锁定屏幕的时间之下.
我也看到了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;
}