Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top