Ios sdk Compatibility Guide is the content to be introduced in this article. It mainly describes how to apply ios sdk-based development instructions to XCode projects. Let's take a look at the details. 1. Use (weakly linked) Weak Connection classes, methods, and functions to support program running between different versions. 2. Weak Connection to the entire framework) 3. Select different compiling conditions for different IOS sdks 4. Identify out-of-date API usage in the Code 5. Determine the operating system and framework at runtime) version 1. When using weak connection classes in IOS to use weak connections of classes in the project, you must ensure the availability of these classes at runtime without causing dynamic connection errors. In Versions later than IOS4.2, NSObject class is used to detect the availability of weak connections in the runtime tense. This simple and efficient mechanism uses the availability macro of NS_CLASS_AVAILABLE. Check whether the latest release framework does not support macros of NS_CLASS_AVAILABLE. In Conditional compilation of macro frameworks that support NS_CLASS_AVAILABLE, you can use the following •. if ([UIPrintInteractionController class]) {•. // Create an instance of the class and use it. •.} else {•. // Alternate code path to follow when •. // class is not available. •.} if you are not sure whether you can use the class method, you can use the NSClassFromString method to determine whether to use the class method. The method is as follows :•. class cls = NSClassFromString (@ "NSRegularExpression ");•. If (cls ){•. // Create an instance of the class and use it. •.} else {•. // Alternate code path to follow when •. // class is not available. •.} 2. Using weak connections in methods, functions, and symbols is the same as using weak connections in classes. before using them, ensure the availability of method functions and symbols at runtime, otherwise, a dynamic connection error will be reported during compilation. If you want to use the features of the new IOS Development SDK but want to run it in the lower version of the SDK, then we need to set the corresponding development target for earlier versions. In Object-c, the
instancesRespondToSelector: Specifies whether the given method is available, for example, using availableCaptureModesForCameraDevice: this method (after 4.0 ). We can use it like this. 1. Check the availability of an Object-c method •. if ([UIImagePickerController instancesRespondToSelector :•. @ selector (availableCaptureModesForCameraDevice :)]) {•. // Method is available for use. •. // Your code can check if video capture is available and ,•. // if it is, offer that option. •.} else {•. // Method is not available. •. // Alternate code to use only still image capture. •.} to determine whether a weak connection C function is available, you only need to determine whether the function address is returned NULL. We can use the CGColorCreateGenericCMYK function as an example. 2. Check the availability of the C method •. if (CGColorCreateGenericCMYK! = NULL ){•. CGColorCreateGenericCMYK (0.1, 0.5.0.0, 1.0, 0.1 );•.} else {•. // Function is not available. •. // Alternate code to create a color object with earlier technology •.} to check whether a C method is available, it is clear that the address is NULL or zero. You cannot use the inverse operator (!) To deny the availability of a function. An external (extern) constant or a notification name should compare its address (address) -- instead of the symbol name, determine whether it is NULL or nil. 3. Weak Connection to the entire Framework, such as a Framework that appears in a later version, wants to use its features in a lower version. Then you must connect to the Framework that you use. For details, see the official illustration --- (in fact, change required of the added Framework to optional )•. http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/XcodeProjectManagement •. 130-Files_in_Projects/project_files.html # // apple_ref/doc/uid/TP40002666-SW4 4. Conditional compilation for different sdks if you compile based on more than one ios sdk, you may need to use conditional for the base pipeline sdk, which can be used in Availability. h. This. H files are stored in the system folder/usr/include. for example, you want to use the CGColorCreateGenericCMYK function in javasmac OS X v10.5 (instead of IOS) to compile using the pre-processing command for condition •. # ifdef _ MAC_ OS _X_VERSION_MAX_ALLOWED •. // code only compiled when targeting Mac OS X and not iOS •. // note use of 1050 instead of _ MAC_10_5 •. # if _ MAC_ OS _X_VERSION_MAX_ALLOWED> = 1050 •. if (CGColorCreateGenericCMYK! = NULL ){•. CGColorCreateGenericCMYK (0.1, 0.5.0.0, 1.0, 0.1 );•.} else {•. # endif •. // code to create a color object with earlier technology •. # if _ MAC_ OS _X_VERSION_MAX_ALLOWED> = 1050 •.} •. # endif •. # endif •.} 5. Searching for outdated instances used in the program sometimes the API in IOS or Mac OS is outdated, but it does not mean that those instances are deleted from the Library or framework, however, a warning is reported during use and may be removed from Apple in the near future. For example, if we use the obsolete function HPurge in the code, the following will be reported •. 'hpurge' is deprecated (declared at/Users/steve/MyProject/main. c: 51) So we should find the following warning in the project and modify it. 6. Determine the operating system and Framework version and check the IOS version at runtime •. NSString * osVersion = [[UIDevice currentDevice] systemVersion]; Check Mac OS X with Gestalt function and System Version constant at runtime. In addition, for many frameworks, you can check the version of the specified Framework at runtime. Example: Application Kit (NSApplication. h) defines the NSAppKitVersionNumber constant. It can be used to check the version of the Application Kit Framework, for example •. APPKIT_EXTERN double NSAppKitVersionNumber ;•. # define NSAppKitVersionNumber10_0 577 •. # define NSAppKitVersionNumber10_1 620 •. # define NSAppKitVersionNumber10_2 663 •. # define NSAppKitVersionNumber10_2_3 663.6 •. # define NSAppKitVersionNumber10_3 743 •. # define NSAppKitVersionNumber10_3_2 743.14 •. # define NSAppKitVersionNumber10_3_3 743.2 •. # define NSAppKitVersionNumber10_3_5 743.24 •. # define NSAppKitVersionNumber10_3_7 743.33 •. # define NSAppKitVersionNumber10_3_9 743.36 •. # define NSAppKitVersionNumber10_4 824 •. # define NSAppKitVersionNumber10_4_1 824.1 •. # define NSAppKitVersionNumber10_4_3 824.23 •. # define NSAppKitVersionNumber10_4_4 824.33 •. # define NSAppKitVersionNumber10_4_7 824.41 •. # define NSAppKitVersionNumber10_5 949 •. # define NSAppKitVersionNumber10_5_2 949.27 •. # define NSAppKitVersionNumber10_5_3 949.33 so we can use it as follows :•. if (floor (NSAppKitVersionNumber) <= NSAppKitVersionNumber10_0 ){•. /* On a 10.0.x or earlier system */•.} else if (floor (NSAppKitVersionNumber) <= NSAppKitVersionNumber10_1 ){•. /* On an a 10.1-10.1.x system */•.} else if (floor (NSAppKitVersionNumber) <= NSAppKitVersionNumber10_2 ){•. /* On a 10.2-10.2.x system */•.} else if (floor (NSAppKitVersionNumber) <= NSAppKitVersionNumber10_3 ){•. /* On 10.3-10.3.x system */•.} else if (floor (NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ){•. /* On a 10.4-10.4.x system */•.} else if (floor (NSAppKitVersionNumber) <= NSAppKitVersionNumber10_5 ){•. /* On an a 10.5-10.5.x system */•.} else {}