我正在开发一个 iphone 应用程序,当应用程序在后台运行时,我必须以编程方式更改锁屏图像。我有很多东西说这是不可能的,但是有一个应用程序可以解决这个问题,请告诉我如何实现这一点.
谢谢。
Best Answer-推荐答案 strong>
更改锁屏图像的唯一方法是在播放音频时。 Police Scanner+ 确实会播放音频,因此可以设置图像。这仅适用于 iOS 5+,并且是这样完成的。
- (void)setupNowPlayingInfoCenterMPMediaItem *)currentSong
{
NSString *ver = [[UIDevice currentDevice] systemVersion];
CGFloat version = 4.0;
if ([ver length] >= 3)
{
version = [[ver substringToIndex:3] floatValue];
}
if (version >= 5.0)
{
MPMediaItemArtwork *artwork = [currentSong valueForProperty:MPMediaItemPropertyArtwork];
MPNowPlayingInfoCenter *infoCenter = [MPNowPlayingInfoCenter defaultCenter];
if (currentSong == nil)
{
infoCenter.nowPlayingInfo = nil;
return;
}
infoCenter.nowPlayingInfo = [NSDictionary dictionaryWithObjectsAndKeys:
[currentSong valueForKey:MPMediaItemPropertyTitle], MPMediaItemPropertyTitle,
[currentSong valueForKey:MPMediaItemPropertyArtist], MPMediaItemPropertyArtist,
[currentSong valueForKey:MPMediaItemPropertyAlbumTitle], MPMediaItemPropertyAlbumTitle,
[currentSong valueForKey:MPMediaItemPropertyAlbumTrackCount], MPMediaItemPropertyAlbumTrackCount,
[currentSong valueForKey:MPMediaItemPropertyAlbumTrackNumber], MPMediaItemPropertyAlbumTrackNumber,
artwork, MPMediaItemPropertyArtwork,
[currentSong valueForKey:MPMediaItemPropertyComposer], MPMediaItemPropertyComposer,
[currentSong valueForKey:MPMediaItemPropertyDiscCount], MPMediaItemPropertyDiscCount,
[currentSong valueForKey:MPMediaItemPropertyDiscNumber], MPMediaItemPropertyDiscNumber,
[currentSong valueForKey:MPMediaItemPropertyGenre], MPMediaItemPropertyGenre,
[currentSong valueForKey:MPMediaItemPropertyPersistentID], MPMediaItemPropertyPersistentID,
[currentSong valueForKey:MPMediaItemPropertyPlaybackDuration], MPMediaItemPropertyPlaybackDuration,
[NSNumber numberWithInt:self.mediaCollection.nowPlayingIndex + 1], MPNowPlayingInfoPropertyPlaybackQueueIndex,
[NSNumber numberWithInt:[self.mediaCollection count]], MPNowPlayingInfoPropertyPlaybackQueueCount, nil];
}
}
关于objective-c - 当应用程序在后台运行时以编程方式更改 iphone 锁屏,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/12835380/
|