Changing iphone lock screen programmatically when app is running in background

后端 未结 2 501
再見小時候
再見小時候 2020-12-29 00:35

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 b

相关标签:
2条回答
  • 2020-12-29 01:02

    there is No way to do this effect unless a app runs in a jailbreak iDevice ( and it means the app can't be submitted to App Store).

    0 讨论(0)
  • 2020-12-29 01:14

    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];
        }
    }
    
    0 讨论(0)
提交回复
热议问题