문제

I'm using [MPMusicPlayerController ipodMusicPlayer] to play songs in my application

so that the song experience doesn't get interrupted even if the app goes to the background.

I've registered MPMusicPlayerNowPlayingItemDidChangeNotification in my app delegate,

so that whenever the music changes I can stop the player for a while, do something, and

then re-play it again.

The problem is, I need to receive the notification even when the app is in the background

and my app is the only application that's using the ipodMusicPlayer. (that is, default music app isn't open).

I've been playing around with applicationDidEnterBackground, but I just can't get it to work.

How should I achieve this?

Thank You in advance

도움이 되었습니까?

해결책

I found a solution for this.

Declare all your notification receivers in your app delegate, along with

[[MPMusicPlayerController iPodMusicPlayer] beginGeneratingPlaybackNotifications];

Then, initialize a CLLocationManager object and start receiving location changes.

This way, your app will not be suspended even if it goes to the background,

and your appdelegate will keep receiving playbacknotifications.

However, if will only work with applications using GPS features.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top