当应用程序在后台运行时,以编程方式更改iphone锁定屏幕 [英] Changing iphone lock screen programmatically when app is running in background

查看:156
本文介绍了当应用程序在后台运行时,以编程方式更改iphone锁定屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iphone应用程序,我必须在应用程序在后台运行时以编程方式更改锁屏图像。我有很多东西说这是不可能但有一个应用程序,请让我知道如何实现这个。

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.

谢谢。

推荐答案

唯一可以改变的方法锁屏图像是在播放音频时。 Police Scanner +会播放音频,因此可以设置图像。这仅适用于iOS 5+并且完成类似的操作。

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. This only works with iOS 5+ and is done something like this.

- (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];
    }
}

这篇关于当应用程序在后台运行时,以编程方式更改iphone锁定屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆