我正在開發一個iphone應用程序,我必須在應用程序在後臺運行時以編程方式更改鎖定圖像。我有很多東西說這是不可能的,但有一個這個應用程序請讓我知道如何實現這一目標。當應用程序在後臺運行時,以編程方式更改iphone鎖定屏幕
謝謝。
我正在開發一個iphone應用程序,我必須在應用程序在後臺運行時以編程方式更改鎖定圖像。我有很多東西說這是不可能的,但有一個這個應用程序請讓我知道如何實現這一目標。當應用程序在後臺運行時,以編程方式更改iphone鎖定屏幕
謝謝。
只有當您播放音頻時,才能更改鎖定屏幕圖像。警察掃描儀+播放音頻,因此可以設置圖像。這隻適用於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)。
但有打電話報了警掃描儀+在AppStore上做這意味着它是acheivable – user1626842
是的,有打不發聲的軌道定製專輯圖像來處理它黑客攻擊的方式相同的應用程序。但這個技巧是沒有意義的,除非你的應用程序是一種音樂應用程序。 – xhan
謝謝,但你能幫助我詳細的方式如何設置圖像時音頻播放background.Please幫我一些源代碼。我由此得到了很多錯誤。 – user1626842
我剛剛創建了一個示例項目,當我遇到[本指南]時(http://jaysonlane.net/2012/04/lock-screen-now-playing-with-mpnowplayinginfocenter/),無論如何它解釋了大部分內容。 我不認爲你可以創建自己的MPMediaItemArtwork對象,所以我想如果你想要一個自定義圖像,你可以創建一個虛擬的mp3文件與圖像,將其添加到您的項目,並創建一個MPMediaItem與該歌曲。然後您可以訪問它的MPMediaItemArtwork屬性,如鏈接所示。 –
@ sam_899:使用您的代碼,我可以將一些信息添加到音樂控件中。你知道如何更新那裏的音樂進程嗎?即使我設置播放時間,進度也不會改變。 –