How to enable iPod controls in the background to control non-iPod music in iOS 4?

Problem is solved.

In short, to enable remote control event, 1) use :

- (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent

and 2) put this is your view controller :

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder {
    return YES;
}

I have to give credit to Grant. He has forked Matt Gallagher’s AudioStreamer enabling all the ios4 improvements (background audio, and remote controls working). You can find his sources along with a working sample on github : http://github.com/DigitalDJ/AudioStreamer

Regarding the icon : once you use beginReceivingRemoteControlEvents, the icon automatically switches to your app icon. Brilliant !

Leave a Comment