IOS SDK Development. Framework Static Library

Source: Internet
Author: User

View. A static library generation and use click here

Note: This tutorial will use only a small portion of the OBJECTIVE-C code, which focuses on detailed steps from start to application.
Environment: Xcode 9.2
Let's start by doing the following:

First step: Create a static library project

Open Xcode, select Create a new project, and create a new cocoa Touch Framework. Name to see their own needs named, I directly called MYSDK.

After creation, there is already an. h file MMYSDK.h and info.plist files, if you want the new implementation method encapsulated into the SDK can be directly created by the new class in the implementation, you can also add their own implementation of the function of the class into the project. (This is just a sketch of the. Framework static library steps, so drag directly into the previously written class, get the IP address of the device,. m inside the specific acquisition method will not go out, if there is a need to directly access the iOS common system Information acquisition method in the IP access section)

Step Two: Modify the SDK project configuration

2.1. Set build Active Architecture in targets-----build setting the corresponding value for debug is No.

2.2. Set the corresponding value for the Mach-o type in the targets-Build setting to the static library static libraries.

2.3. Set the corresponding value of dead Code stripping in targets-Build setting to No. (roughly meaning that if you turn this on, the code in the code "Dead", "unreachable" is filtered, but whether the switch is off, it doesn't seem to have much effect, but to completely restore the code in the framework, it is not necessary to close the item)

2.4, set the link with the standard libraries in targets-Build setting with the corresponding value of no, avoid duplicate links.

2.4. Move the header file that will need to become visible in targets-Build phases to public.

2.5. Add the header file that can call the method directly into MYSDK.h.

Step three: Build the. Framework Static Library

Static library is divided into two kinds of mobile phone and simulator (mobile phone can only call, simulator only can call)

3.1. Build simulator use static library, choose an emulator at will, then compile the project (shortcut key command + B). This time has been generated only in the simulator can be used. A static library mysdk.framework.

3.2, the same reason to choose generic IOS device to generate the real function of the. a static library.

Right-Mysdk.framework, select the show in Finder under the Products folder has two folders Debug-iphoneos and Debug-iphonesimulator, respectively, the real machine and emulator corresponding to the static library.

Fourth step: synthesizing generic. A static library

The MYSDK Static library inside the real machine and simulator Mysdk.framework is merged into a common static library, which is completed at the terminal. Using the command line: lipo-create mysdk Static library path simulator MYSDK static library path-output synthetic static library path (directly drag mysdk file path can appear in the terminal).

At this point, the final composite library has been generated under the Debug-iphoneos folder, replacing the MYSDK under Mysdk.framework with the newly generated mysdk. Mysdk.framework is the static library we will eventually use. can be used directly.

Fifth step: Use of the framework static library

5.1. Create a project at will, add the synthesized. Framework Static library to the project (this is just a description of the use of static libraries, ignoring the project directory structure). Then import the header file inside the Viewcontroller to invoke the method inside the static library

5.2, respectively in the simulator and mobile phone run (iphone x simulator and iphone 6S mobile phone), the results are as follows (please ignore the page layout, just to show the results).

At this point, you are done.

IOS SDK Development. Framework Static Library

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.