How to break code for iOS 3.0 and iOS 3.2 so that I can use MPMoviePlayerViewController if OS 3.2 ++

I have a video that I play. To use full screen mode in iOS 3.2, I use MPMoviePlayerViewController (it seems to work only with this class). But if I want to build for iOS 3.0, I obviously get a few errors, because this class is unknown in iOS 3.0. I also know how to get what I want with MPMoviePlayerController in iOS 3.0, but I can only have iOS 3.0 code or iOS 3.2 code.

How to handle this? - solution found (see bottom of nested editing)

I assume that I need to use several goals, do you have any suggestions on how to do this (always, when I tried several goals, I got errors and gave up :))?


Edit bundled (several editable changes)

At first I thought it would work.
#ifdef __IPHONE_3_0
// OS 3.0 specific
#endif

But this is not because in the iOS Availability.h files you have all the OS defined from 2.0 to your current. Therefore, if you compile iOS 3.2, #ifdef __IPHONE_3_0 will also return true.

Then I thought it would work

#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_2
  // Code for older iOS
#else
  // Code for iOS 3.2 up
#end

But this is not so. Because in iOS 3, for example, __IPHONE_3_2 is undefined.

So, I thought that I would have to create an even more intelligent if / elseif / else block, but then I (finally: D) read the comment above __IPHONE_X_X in the boxes. AvailabilityInternal.h file definitions:

, __IPHONE_OS_VERSION_MIN_REQUIRED , __IPHONE_X_X - , ... , , 0. . , ...

,

( 100%)

#if __IPHONE_OS_VERSION_MIN_REQUIRED < 30200
  // code for iOS below 3.2
#else
  // code for iOS 3.2 ++
#endif
+3
2

, , , Apple iPad, API-, NSClassFromString, . , ( ), ,

Class mplayerControllerClass = NSClassFromString(@"MPMoviePlayerViewController");
if(mplayerControllerClass != nil) {
   //Code for 3.2, e.g. [mplayerControllerClass alloc]
} else {
   //Code for pre-3.2 OSes
}
+5

...

#ifdef IPHONE_OS_3.2

/* iOS 3.2 code */

#endif

#ifdef IPHONE_OS_3.0

/* iOS 3.0 code */

#endif

... , .

0

Source: https://habr.com/ru/post/1749495/


All Articles