views:

1038

answers:

1

my device are running on OS4 GM and it not present Mediaplayer when play. when test on os3.1.3 it work well. when i target to deploy on OS4 it will resolve this issue, how can i fix it?

Here is my code .h

  #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_3_2
MPMoviePlayerController *theMovie;
  #endif
//On a 4.0 device, implement the MPMoviePlayerViewController
  #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
MPMoviePlayerViewController *theMovie;
  #endif



//If iPhone OS is 3.1 or less, implement the MPMoviePlayerController
  #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_3_2
@property (readwrite, retain) MPMoviePlayerController *theMovie;
  #endif
//On a 4.0 device, implement the MPMoviePlayerViewController
  #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
@property (readwrite, retain) MPMoviePlayerViewController *theMovie;
  #endif

.m

 #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_3_2

                    NSLog(@"__IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_3_2");

                    AppDelegate = nil;

                    AppDelegate = [[UIApplication sharedApplication] delegate];

                    [AppDelegate ForceHideNavigationBar];

                    theMovie = nil;

                    // Register to receive a notification that the movie is now in memory and ready to play

                    [[NSNotificationCenter defaultCenter] addObserver:self 

                                                                       selector:@selector(moviePreloadDidFinish:) 

                                                                            name:MPMoviePlayerContentPreloadDidFinishNotification 

                                                                         object:theMovie];



                    // Register to receive a notification when the movie has finished playing. 

                    [[NSNotificationCenter defaultCenter] addObserver:self 

                                                                       selector:@selector(moviePlayBackDidFinish:) 

                                                                            name:MPMoviePlayerPlaybackDidFinishNotification 

                                                                         object:theMovie];



                    // Register to receive a notification when the movie scaling mode has changed. 

                    [[NSNotificationCenter defaultCenter] addObserver:self 

                                                                       selector:@selector(movieScalingModeDidChange:) 

                                                                            name:MPMoviePlayerScalingModeDidChangeNotification 

                                                                         object:theMovie];



                    theMovie = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:AppDelegate.PushLink]];

                    theMovie.scalingMode = MPMovieScalingModeAspectFill;
                    [theMovie play];



  #endif               

                    //On a 4.0 device, implement the MPMoviePlayerViewController

  #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2

                    // Initialize a movie player object with the specified URL

                    MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:AppDelegate.PushLink]];

                    if (mp) {



                         self.theMovie = mp;

                         [mp release];

                         //Present

                         [self presentMoviePlayerViewControllerAnimated:theMovie];



                         // Play the movie!

                         self.theMovie.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

                         [self.theMovie.moviePlayer play];

                    }

  #endif
+2  A: 

I you want to target both iOS3 and iOS4, you don't want to use conditional compilation (#if statements). Conditional compilation resolves at compile time but you want something that can change its behavior at runtime based on which system the user is running.

You actually want to use "weak linking".

  1. Set your Base SDK to iOS4. Set the iPhone OS Deployment Target to iOS3
  2. Declare both properties but in your code check if ([MPMoviePlayerViewController class] != nil). If it's not nil, use the MPMoviePlayerViewController, otherwise, use the old one.

For more on weak linking, see:

Matt Gallagher
thanks Matt Gallagher
RAGOpoR
i have a problem when integrate iAd when deploy on os3 it have some error like this *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (ADBannerView)'
RAGOpoR