Developing iPhone apps with ios4 SDK, deploying to 3.x devices: Base SDK and iPhone OS Deployment t

Source: Internet
Author: User
If you 've installed xcode 3.2.3 you quickly became aware that
Only SDK's packaged with this version are 4.0 and 3.2. Until 4.x has
Widespread adoption, chances are you'll want your applications to run on
Earlier versions of the iPhone OS (IOS) SDK. You can accomplish this
Feat through two configuration options within xcode, the base SDK and
The iPhone OS Deployment target.

Base SDK

The base SDK is the version of SDK that will be used when compiling
Your application-the compiler will use the headers and libraries
This specific SDK. For example, in the image below notice that there are
Only two choices for the base SDK for both the device and simulator,
Versions 3.2 and 4.0.

However, we have an issue here, if you build an application with
Latest SDK and deploy on a device with an earlier OS, chances are your
Application will crash if you reference any code in a 4.x API while
Running the application on a 3.x device. Also, the 3.2 SDK is for
IPad only, so this isn' t an option when deploying to an iPhone or iPod
Touch.

IPhone OS Deployment target

To specify which OS version is the minimum that your application will
Support, you set the deployment target. Your application will then run
On this minimum OS as well as all later versions.

This is all well and good, however, the obvious question is how
Deploy on an earlier OS version yet take advantage of features for those
Devices that are running a later OS?

Check for feature availability not OS version

When targeting an earlier OS as mentioned above, yet you want to take
Advantage of features of a later OS for devices that support it, you
Can use the methodRespondstoselectorTo check if
Extends er implements or inherits a method that can respond to
Specified message. This approach follows Apple's recommendation to check
For availability of features versus a specific OS version.

In the example below the code will check if the object returned[Uidevice currentdevice]Will respond to the selector shown, if so, you can write relevant multi-tasking code:

  If   (  [  [ uidevice currentdevice ]  respondstoselector :   @ selector   ( ismultitaskingsupported )  ]  )  { // multi-tasking code for supported devices  }  else  {  // devices without multi-tasking support  } 

Another time when that you may choose to useRespondstoselector
Is for cases when the implementation of the same API has changed with
Later OS version. I ran into this special case when writing code
Displaying movies usingMpmovieplayercontroller. In the 4.x SDK the communications have changed slightly-In 2.0 to 3.1MpmovieplayercontentpreloaddidfinishnotificationWas the notification you wocould use to receive notice that a movie was ready to play. With 3.2 (IPAD) and later,MpmovieplayercontentpreloaddidfinishnotificationHas been deprecated andMpmovieplayerloadstatedidchangenotificationHas taken its place.

The code example below shows how you may go about usingRespondstoselector
To figure out which notification you shoshould request based on
Whether or not the movie player can return information about its load
State:

Mpmovieplayercontroller * MP =      [  [ Mpmovieplayercontroller alloc ] Initwithcontenturl : Movieurl ] ; // This method is available on 3.2 and greater...   If   (  [ MP respondstoselector :  @ Selector ( Loadstate )  ]  )   {    // Register to receive notification when load state changed    // (Check for playable, stalled ...)    [  [  Nsnotificationcenter Defacenter Center ] Addobserver : Self Selector : @ Selector  ( Movieplayerloadstatechanged :  ) Name : Mpmovieplayerloadstatedidchangenotification object :  Nil  ] ; }  Else  {    // Register to receive a notification when the movie is ready to play.    [ [  Nsnotificationcenter Defacenter Center ] Addobserver : Self Selector :  @ Selector  ( Moviepreloaddidfinish :  ) Name : Mpmovieplayercontentpreloaddidfinishnotification object :  Nil  ] ; } 
Check for function availability

Beyond working with objects, if you need to check for
Availability of a specific function, you do so by comparing the Function
To null. In the example below I check for a function related
Creating a PDF-based graphics context (available in 3.2 and later ).

 
If (Uigraphicsbegin1_contexttofile! = Null){// The function is available}
Testing authentication ss OS versions

Unfortunately, with the upgrade to the latest xcode (3.2.3) there are
No simulators for 3.1.x and earlier OS versions. Although it has always
Been recommended to test your apps on device, at this point it becomes
Necessity.

Http://iphonedevelopertips.com/xcode/base-sdk-and-iphone-os-deployment-target-developing-apps-with-the-4-x-sdk-deploying-to-3-x-devices.html

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.