Notes for supporting multiple versions and devices in IOS

Source: Internet
Author: User

Notes for supporting multiple versions and devices in IOS

The IOS system has been available for six years since. It has been released once a year to two new devices, from iPhone E1, iPhone E2... iphone4s to the latest iPhone 5. The CPU architecture may also change during the hardware upgrade, for example, the earliest armv6 and armv7 with the latest iphone5, so armv7s is used. At the same time, with each hardware upgrade, the system will perform a major version upgrade. Currently, the latest version has reached 6.x.

During each system upgrade, some users are reluctant or unable to upgrade to the latest system for various reasons. This means that ifProgramTo be used by as many people as possible, you must support as many hardware architectures and system versions as possible. If we write less programs and less hardware, We need to configure ubuntures in the project options and add the hardware architecture that we want to support.However, each system upgrade will be accompanied by the introduction of many new APIs, frameworks, and some old APIs. That is to say, the more system versions we want to support, the larger the workload, So we usually make a trade-off based on the workload and distribution of system versions. Now, basically, apps in the appstore generally support IOS 4.3 systems at most. In my previous project, powercam also supports IOS 4.0.

We will discuss it in two aspects:

1. Support for multiple device types

The CPU instruction sets of different devices may be different, which may lead to different supported frameworks. For example, the CPU of iPhone 3G and earlier devices only supports armv6 instruction sets. As a result, these devices only support OpenGL ES 1.1, all iPad and iPhone 3gs devices use armv7 and armv7s (iphone5, ipad4) instruction sets. Therefore, OpenGL ES 1.1 and 2.0 are supported.

How to Set it? In the targets buildsetting of the xcode project, there is a ubuntures, through which we set the device types supported by the project. Currently, the latest xcode 4.5 project is created with the default value "Standard (armv7, armv7s)", which supports all devices after the iPhone 3gs. If your program needs to support iphone3g, You need to edit this option. Click this option and select others to edit it. Add armv6. As shown in:

Ii. multi-system versions supported

In xcode's project compilation options, we can see two options: Base SDK and deployment target. The first option is to set the SDK development version of our project, the second option is used to set the minimum operating system on which the project can be deployed.

The most used SDK and the latest version are usually used in the project created by xcode. Because we need to support both the new version and the old version that our colleagues have taken into account. In order to be able to take advantage of the new features in the new version, we 'd better select the latest SDK, which is usually not required to be changed, keep it as it is. To support earlier versions, you must modify the deployment target option. As shown in, we need to set the latest version of the project to iOS 4.3.

Once this is done, xcode will compile and package based on our settings. Here we will discuss how xcode uses the latest SDK, but can support older system versions? Check the documentation SDK Compatibility Guide and find that during program packaging, xcode only pushes some exported symbols to our package. The actual system version of the device is matched during running. There is a diagram in the document that explains how the base SDK and deployment target operate, such:

This figure uses the Mac OS project as an example, but the principle is the same. This means that we can use all the APIS before the deployed version unconditionally (it is best to use the new API in the new version ), whether or not the API between the version we support deployment and the SDK version we develop depends on the system version that our app runs.

During system version upgrade, some new APIs and frameworks are usually added, and some old inefficient APIs are also discarded. Although these obsolete APIs cannot be immediately unavailable, they are not guaranteed to be supported in later versions. Therefore, to make our programs more reliable in the new system, for efficient operation, we should try our best to use new APIs.

Whether it is to call APIs that are not supported in the new system version or to call the APIS introduced in the new system version in the old system version, our program will be crush. Therefore, when calling the APIS or frameworks we have added after the deployed version, we need to determine whether the environment in which the current program runs is supported.

Below we will discuss from several aspects:

1) determine whether a class is available

After IOS 4.2, we can use the class method to determine whether a class is available at the current runtime,CodeAs follows:

 
If([UicollectionviewClass]) {//6.0 and later}Else{//In earlier versions, alternative technologies must be used for implementation.}

In Mac OS, you need to useNsclassfromstring to determine whether a class is available.

2) determine whether a method is available

The nsobject class has a method instancesrespondtoselector that can be used to determine whether a class instance responds to a specified method. To determine whether a Class responds to a class method, you can use the respondtoseletor method. The Code is as follows:

 
If([Uiviewcontroller instancesrespondtoselector: @ selector (presentviewcontroller: animated: Completion :)]) {//Supported after 5.0}Else{//This method is not supported}

3) determine whether a function is available

We know that every function name in C language represents the address of this function, so we can judge whether the function name is null to support this function.

 
If(Cgcolorcreatecopywithalpha! =Null ){//This function is supported.}Else{//This function is not supported.}

4) determine whether an extern variable or notification name is available

The extern variable and notification name are both variables. You only need to determine whether the address is null. The Code is as follows:

If(& Mpmovieplayerreadyfordisplaydidchangenotification! =Null ){//This notification exists after 6.0}Else{//The notification does not exist.}

 

This document also describes how to implement Conditional compilation for different SDK versions by using macros. If you are interested, you can take a look at it by yourself.

Now, the considerations for multi-version, multi-device, and multi-device support are described. I hope this will help you.

Reference:SDK Compatibility Guide

Note: Please indicate the source for reprinting! Welcome to join me in QQ 1592232964 to discuss common progress.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.