IOS7 Development ~XCODE5 Production Framework

Source: Internet
Author: User

I. Introduction to the framework (Introduction to the Framework Programming Guide)

Mac OS X extends the framework's capabilities so that we can use it to share code and resources. Through the framework we can share all forms of resources, such as dynamic shared libraries, nib files, image character resources, and documents. The system loads the framework into memory when needed, and multiple applications can use the same framework at the same time, with only one copy in memory. A framework is also a bundle, which we can browse through in the Finder, or access it through NSBundle in code. With the framework we can implement dynamic or static library functions.

Translation: https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPFrameworks/Frameworks.html

Ii. Framework method of production

1, the first new two projects, respectively, Frameworkhome and Frameworkdemo, of which frameworkhome for the framework project, Frameworkdemo for the framework Test project.

(1) Establish Frameworkhome (select Static Library template)

A, select the project template

B, clean-up Works useless files (Target, Frameworkhome, frameworkhometests)

Before deletion:

After deletion:

C. Delete the compilation settings for the old target

Click Manage Scheme

In the lower left corner, click "-"

Select Delete and click OK

D. Add a new target

Click Add Target

Select Templates

Click Next, and the configuration does not need to change, start a name, then click Finish

Results

E. Modify the project configuration

Click Target created in step D and choose Build Settings-Architectures-C to latest iOS (iOS 7.0)

and change architectures to standard architectures (ARMV7, armv7s)

Under Deployment, change "Mac OS X Deployment Target" to "Compiler Default", change "targeted Device Family" to desired, change it to "Iphone/ipad", and Modify "iOS Deployment Target" as needed and change it to "iOS 5.0" here:

In linking, change "Dead Code stripping" to "no", change "Link with standard Libraries" to "no", change "Mac-o Type" to "relocatable Object" File ":

Packaging, change "Wrapper extention" to "framework":

Modify Info to change "Bundle OS Type Code" to "Fmwk" (Framework)

Modify the precompiled header file to gaze at the code

So far, the basic configuration even if finished, you can see the present products in the file for Demolibrary.framework, good, this is to frameworkdemo use of framwwork, Although now Frameworkdemo has not yet been created. But before that, we first write some demolibrary.framework and then provide the interface to Frameworkdemo.

F, provide external interface

First of all, create a class, it is recommended not to use Ixib, because later packaged into the framework, I encountered Viewcontroller cannot find the Xib file, so it is not recommended to use Xib.

Create two Viewcontroller, respectively, Openviewcontroller and Praviteviewcontroller, where Openviewcontroller is an externally exposed interface, and the internal implementation uses the Praviteviewcontroller.

Don't forget to choose target

G, lead-out file

Check Target (demolibrary), Build phases-> Editor-> Add build Phase-> Add copys Headers Build Phase

Expand "Copy Headers"

Click "+" in the lower right corner to select the appropriate. h file to add an external interface

and drag the files under Project to public.

It's done, but there's a detail in this place. Note that the framework of the current selection build is to select iOS Device, do not select the real machine you are currently linking to, or it will occur when the packaged framework is used on another machine.

In addition, the current framework is suitable for the real machine, if you want to do the framework of the simulator, to modify the emulator version

Now you can build the Frameworkhome project!

This place has a little trick, when the simulator, build, found that the file under the products is still a red font, indicating that it does not exist, in fact, the file has already. The simulator replaced with Devixe, and then build, you will find Demolibrary.framework font black, indicating that the file has, with the Finder to find the location:

The framework in Debug-iphoneos is the real machine version, the bottom folder is the emulator version.

2, the Establishment Frameworkdemo project, chooses the empty application template to be possible, will just generate demolibrary.framework Copy (can also be referenced) drag to Frameworkdemo and run Frameworkdemo. There's a little detail in this place, Frameworkdemo->target-> architectures the settings are the same as in the framework, otherwise the problem occurs.

Compile run:

Console printing:

Add: In general framework projects, there will be some pictures and other resources to be provided to the user together, then you need to package these resources into bundle files, and the framework is copied to the corresponding project.

1. Build Bundle file

New folder, put the picture resources in the folder-> change the folder name to Xxx.bundle, and then put the bundle file together in the target project.

2. Read the file

The code in the framework is going to read the file like this, and of course there are other ways to initialize the path, which can be supplemented later.

    1. NSBundle *bundle = [NSBundle bundlewithurl:[[nsbundle mainbundle] urlforresource:@ "Resource"   Withextension:@ "bundle"];
    2. UIImage *img = [UIImage imagewithcontentsoffile:[bundle pathforresource:@ "testimg" ofType:@ "  PNG "]];
    3. [Viewctr. View addsubview:[[uiimageview alloc] initwithimage:img];

3. Some wrong solutions

Http://stackoverflow.com/questions/14367793/duplicate-symbol-error-in-xcode

duplicate symbol _NXArgcin:    解决办法:Please set the option "Link with Standard Library" to NO in your build setting

Also refer to: http://blog.csdn.net/lizhongfu2013/article/details/12912807

4, the establishment of a real machine and simulator common framework

First Use Finder to find the location of the framework

Then find the file in the framework, such as Kalagame-library here, and record its path Os_frame_path

The same method opens another folder, recording the path of the library, Simulator_frame_path

Then open the console and enter Lipo-create Os_frame_path simulator_frame_path-output newframe

This completes the combination of the simulator and the real machine version framework, finds the newframe with the Finder, and then changes the Newframe name (for example, Kalagame-library here) and puts it back in the framework folder to replace the original file.

Supplement (2013/12/20):

1, in the production of the framework or LIB, if the use of category, the use of the FMWK program will be crash, at this time need to be in the project other linker flags to add two parameters-objc-all_load

2, compile the framework is, need to generatedebugsymbols =no,project and Target are set under, otherwise there will be a lot of warning:

Similar

Warning: (ARMV6)/users/myuser/library/developer/xcode/deriveddata/.... build/objects-normal/armv6/imagerequest.o Unable to open object file

iOS Static library Why the code is only 700k, the final compilation of 3.4m.

Reason

1: Select the debug mode, after changing to release mode, the estimate can be reduced a lot.

The 2:ios Static library is a static repository that contains all the references to the code, so the extra size is the size of the referenced code. So when you change to release, the size is not fixed, depending on how much of the code you quoted.

Supplement (2014/01/03):

Public of the class, but private class refers to the class, so after packaging, the external error, said the private class can not be found. You can put the import "private.h" in the public's. m, so you don't get an error.

From: http://www.cnblogs.com/heyonggang/p/3513479.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.