Earlier versions run in later versions -- (later versions are compatible with earlier versions)

Source: Internet
Author: User

From http://www.cnblogs.com/vinceoniphone/archive/2010/07/05/1771282.html

 

How to link a framework with weak (high version is compatible with low version)

Apple has an example of mailcomposer, which indicates that new features are called in High-version OS and can still be run in lower-version OS. The important point is weak link messageui. framework.

 

How to weak link? The example is not explicitly stated. I searched for a long time and did not find it. Finally, I accidentally found it.

 

Method:

 

Expand targets, <yourapp>, link binary with libraries in the groups & files on the left of xcode. Note that do not click any framework, but select their parent node "Link ".
Binary with libraries ". At this time, you will find a column in the list in the upper right corner called" role "and set the role of the framework you need weak link to weak.

 

Here, we will recall how to call the objects in weak linked framwork.

 

In the mailcomposer example, we add messageui. framework and set weak link. Then reference the header file

 

# Import <messageui/messageui. h>

 

# Import <messageui/mfmailcomposeviewcontroller. h>

 

 

Let mailcomposerviewcontroller inherit mfmailcomposeviewcontrollerdelegate and create an object in a method:

 

 

Class mailclass = (nsclassfromstring (@ "mfmailcomposeviewcontroller "));

 

If (mailclass! = Nil)

 

{

 

// IOS 3.0, call Methods

 

If ([mailclass cansendmail])

 

..

}

Else

{

// IOS 2.x

}

 

 

 

For specific code, see: http://developer.apple.com/iphone/library/samplecode/MailComposer/Introduction/Intro.html

****************** The following is my sharing of practical experience after reading the blog ********** *************************

Seeing this blog, the project was resolved on ios4.

First, the iphone ios4 remains relatively large in the private library, and some private libraries have been abandoned, therefore, the program compiled in earlier versions may directly collapse when it is run on ios4 (the reason is that the class called by the program, such as PLPhotoPicker, cannot be found on ios4 ),

So if you introduce the Framework in the program as required rather than weak, it may be in the code.

[[PLPhotoPicker alloc] init]; this object will crash directly, although the program has not yet called the part of this Code (because when the required program is up, it will first go to/var/mobile/Library on ios4... in PrivateFrameWork (do not know if this class is already in), so use objcRuntiem in the program

Class mailClass = (NSClassFromString (@ "MFMailComposeViewController "));

To avoid the direct call crash.

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.