简体   繁体   English

当应用程序在后台运行时,以编程方式更改iPhone锁定屏幕

[英]Changing iphone lock screen programmatically when app is running in background

I am developing an iphone app where i have to change lockscreen image programmatically when app is running in background.I have got lots of stuff saying it is not possible but there is an app for this please let me know how to acheive this. 我正在开发一个iPhone应用程序,其中当该应用程序在后台运行时,我必须以编程方式更改锁屏图像。我有很多东西说这是不可能的,但是有一个适用于此的应用程序,请让我知道如何实现。

Thanks. 谢谢。

The only way you can change the lockscreen image is when you are playing audio. 更改锁屏图像的唯一方法是播放音频。 Police Scanner+ does play audio, and therefore can set an image. Police Scanner +确实会播放音频,因此可以设置图像。 This only works with iOS 5+ and is done something like this. 这仅适用于iOS 5+,并已完成类似操作。

- (void)setupNowPlayingInfoCenter:(MPMediaItem *)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];
    }
}

除非应用程序在越狱的iDevice中运行(这意味着该应用程序无法提交到App Store),否则无法实现此效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM