views:

92

answers:

2

How can this Possibly return non-nil on iPhone 3.1.3 (3g iPhone)?

- (BOOL) isIOS3_2OrAbove 
{
 Class mplayerControllerClass = NSClassFromString(@"MPMoviePlayerViewController");
 if(mplayerControllerClass != nil) 
 {
  NSLog(@"MPMoviePlayerViewController not showing NIL!  It is: %@\n",[mplayerControllerClass description]);
  return YES;
 }
 else 
 {
  NSLog(@"MPMoviePlayerViewController is showing NIL!\n");
  return NO;
 }
}

I get this returned:

MPMoviePlayerViewController not showing NIL!  It is: MPMoviePlayerViewController

How can this possibly happen? I am on XCode 3.2.3 running the device over USB.

Here is the code calling it:

NSString *movieName = @"litedefault.mp4";

if ([self isIOS3_2OrAbove] == YES)
{
 movieName = @"litedefault_3_2.mp4";
}

NSString *moviePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:movieName];

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath ]];

moviePlayer.movieControlMode = MPMovieControlModeHidden;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(set_up_views:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];  

if ([self isIOS3_2OrAbove] == YES)
{
 NSLog(@"IS iOS3.2 or above\n");
 moviePlayer.view.frame = CGRectMake(0, 0, 320, 480);
 [window addSubview:moviePlayer.view];
 [window makeKeyAndVisible];

}
else
{
 NSLog(@"IS BELOW iOS3.2\n");
}
[moviePlayer play];

Understand that I am wanting to test for ANY device over 3.2, so i am not testing UI_USER_INTERFACE_IDIOM, for instance. As you see, 3.2 or above requires adding the MPMoviePlayerController to a view.

Any ideas?

Addendum:

It seems that we must check for a class that is NOT a private APi (in a prior iPhone OS release). I tested UILongPressGestureRecognizer (which is actually present, but private in 3.1.3) as well and got a non nil result.

OKAY.... so, this question basically just changed to: Anyone know an API that I can check for that is NOT in 3.1.3 (or earlier)?

URGH!

+1  A: 

I think the question you're actually asking is about how to determine whether you're running on iPhone OS 3.2 or higher. Why not simply use -[UIDevice systemVersion]?

Chuck
OMGosh! I did not think it would be that easy. Shows thatI should not have been programming without caffeine. Thanks!
Jann
A: 

I use it with success.

if ([MPMoviePlayerController instancesRespondToSelector:@selector(view)])
bozi
He's talking about MPMoviePlayerVIEWController not MPMoviePlayerController which is old.
David van Dugteren