views:

405

answers:

1

Hello,

During the testing of my app i discovered that it crashed on an iphone with OS 3.0.1 and 3.1.1(iPod Touch).

I have the following code for playing the video which is placed on a remote server. It works flawlessly on the iOS 4.0 and iPad with OS 3.2

Xcode is setup to use SDK 4.0 but target OS is 3.0.

NSURL *url = [NSURL URLWithString:selectedLink];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; [self presentMoviePlayerViewControllerAnimated:moviePlayer]; [moviePlayer release];

When run on 3.0.1 and 3.1.1 I receive the following error:

-[UIViewController presentMoviePlayerViewControllerAnimated:]: unrecognized selector sent to instance 0x231550
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:  -[UIViewController presentMoviePlayerViewControllerAnimated:]: unrecognized selector sent to instance 0x231550'

Hope you guys can help me.

+4  A: 

MPMoviePlayerViewController has been added recently and is available in iPhone OS 3.2 and later.

You should use MPMoviePlayerController.

Charter
solved it by using:if ([self respondsToSelector:@selector(presentMoviePlayerViewControllerAnimated:)]) { // The new way of playing movies }else { // The old way of playing movies }
objneodude
Fantastic! OK, possibly ignorant followup question coming up here, and I think it's related to this test objneodude just shared:I know I can check selectors, and that's great and all, BUT is there a way for me to check if a _Class_ is supported? For example, given an app with a base SDK of 4.0, but can be run on 3.0+, it's possible to alloc/init a MPMoviePlayerViewController. (It will also not work, but you can instantiate it!)Perhaps the only sanity check is to test for properties on that class? I could look at SDK versions, but I sense it isn't always wise to do that. Thoughts?
Joe D'Andrea