views:

28

answers:

0

Hello There,

I'm writing games onto IPhone platform and want to leverage the "Play ITunes music while running your app" feature. This is something introduced in OS 3.0 but I want to target OS 2.2.1 with sacrificing that feature, as well.

I'm compiling against 3.0 and have the minimum support set to OS 2.2.1. I also weak referenced "Mediaplayer.framework" to use "MPMusicPlayerController" and already weak referenced as well. What I'm not sure, and can't test, is the following code and whether it'll run without any problem on OS 2.2.1. Can anybody give any advice about this?

    Class MyMPClass = NSClassFromString(@"MPMusicPlayerController");
id *MyMPController = [MyMPClass iPodMusicPlayer];

if (MyMPController != NULL)
{
    if ([MyMPController playbackState] == MPMusicPlaybackStatePlaying)
    {           
        ShouldContinue = NO;

        UIAlertView *MyAlert = [[UIAlertView alloc] init]; 
        [MyAlert setTitle:@"Playing music detected!"];
        [MyAlert setMessage:@"A playing music has been detected. Would you like to continue listening it?"];
        [MyAlert setDelegate:self];
        [MyAlert addButtonWithTitle:@"Yes"];
        [MyAlert addButtonWithTitle:@"No"]; 
        [MyAlert show];
        [MyAlert release];
    }
}