即使在网络问题中设置锁定屏幕时我也没有遇到任何问题。
我也在处理流媒体。
而且我认为锁定屏幕仅在音频会话处于活动状态时才会受到影响。
在这里你可以看到我的代码,我没有遇到任何问题希望这对你有帮助。
-(void)setLockScreen
{
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter)
{
[[AVAudioSession sharedInstance] setActive:YES error:nil];
NSError *myErr;
if (![[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&myErr])
{
// Handle the error here.
NSLog(@"Audio Session error %@, %@", myErr, [myErr userInfo]);
}
else
{
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:imgViewLogo.image];
NSArray *keys = [NSArray arrayWithObjects:
MPMediaItemPropertyTitle,
MPMediaItemPropertyArtist,
MPMediaItemPropertyArtwork,
MPNowPlayingInfoPropertyPlaybackRate,
nil];
NSArray *values = [NSArray arrayWithObjects:
[[self.arrChannel objectAtIndex:[AppDelegate sharedAppDelegate].selectedRow] objectForKey:@"name"],
[[AppDelegate sharedAppDelegate].dictChannelsConfig objectForKey:@"venueName"],
albumArt,
[NSNumber numberWithInt:1],
nil];
NSDictionary *mediaInfo = [NSDictionary dictionaryWithObjects:values forKeys:keys];
keys = nil;
values = nil;
albumArt = nil;
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];
mediaInfo = nil;
}
}