iOS Project feature module encapsulates SDK usage summary

Source: Internet
Author: User

First, the Function Module SDK encapsulation steps:

1. Create an iOS framework project

First we need to create an iOS Cocoatouch project, click Next and enter the name of our framework. Let's name the framework "Createloginsdkframework" for the moment. The operation is as follows:

xcode--"file\new\project--"ios\framework and Library\cocoa Touch framework--"name Project Project-" Save directory

2. Set the compatible version:

After the project is created, we will choose "Deployment Target", here we choose 8.0. This means that the iOS system version supported by our Encapsulated SDK is ios8.0+. The operation is as follows:

xcode--"project--"targets--"general--" Deployment info--"ios8.0 (minimum supported compatible version)

3. Configure the Static library:

Since the framework created by default is a dynamic library, we want to say Mach-o type is set to static library "static Libraries". The operation is as follows:

xcode--"project--"targets--"Build settings--"mach-o type--"Static Library

4. Import the source code files and compile them:

The pre-prepared SDK source code is introduced into our framework's project to compile, before compiling we will select the files that the SDK user can see. Set in the headers under build phases. Place the user-visible header file in public, which the user cannot see in project. The operation is as follows:

xcode--"project--"targets--"Build phases--"headers--"public/private/project "

5. Compiling project:

Once setup and configuration is complete, we will compile our Framework work . First select the emulator to compile, then select the real machine to compile. After compiling, the appropriate framework is generated under the products and then viewed through the show in finder. When viewing, if you want to see the "simulator" and "Real machine" framework, after the show in Finder, you need to go to the upper folder to view.

6. Merging the Framework Library :

Because compiling under the emulator generates the framework used under the emulator, compiling under a real machine generates the framework used by the real machine. If we want to create a framework that can be used either under a real machine or under a simulator, then we need to merge the two frameworks. Use the terminal command to merge the above two files. Below is the execution command to merge the above two files, which will generate a new merged file after executing the command below. The operation is as follows:

Open Terminal--"lipo-create Simulator Framework path True machine Framework path-output new file

7. Precautions :

1, before compiling the framework project, you need to set the edit Scheme, select run-> to change the debug mode to release mode, select Close.

2. Merge framework appears Error:can ' t map input file:xxxframework.framework/(Invalid argument), The reason is to customize the FrameworkName if the project name is different from the target name of the framework.

Lipo-info Xxxframework.framework/xxxframework or

CD Xxxframework.framework

Lipo-info Xxxframework

The complete command is as follows:

Lipo-create "${device_dir}/${fmk_name}" "${simulator_dir}/${fmk_name}"-output "${install_dir}/${fmk_name}"

Second, the resource file bundle encapsulation steps:

1, the creation of the bundle project:

Create a bundle project like creating a framework project first, because there are no bundle types of projects under iOS engineering, so we need the framework & Library, OS X, Bundle below to create our bundle project. The operation is as follows:

xcode--"file\new\project--"macos\framework and library\bundle--"named Project Project--" Save directory

2, Configuration Bundle project:

After the bundle project is created, we will configure it accordingly. Since we are selecting the bundle created by OS X, the default bundle is not available in iOS, so we have to set the base SDK to select the appropriate iOS version, as shown below. After selecting the base SDK, we will also set up the iOS version to be compatible (iOS Deployment Target), just like the package in the framework above. The operation is as follows:

A, xcode--"project--"targets--"Build settings--"Base sdk--"ios8.0

B, xcode--"project--"targets--"general--" Deployment info--"ios8.0 (minimum supported compatible version)

3. Import the resource file for compiling:

After the above configuration, the next step is to introduce a resource file for compiling, and the resource file introduced below is our loginsdk.storyboard. After the introduction of the resources, compile, compile will be generated under the products of the corresponding bundle resource file, the file can be used with our framework.

4. load the bundle resources in the project:

After the bundle resource file is generated, we will load the resources from the bundle resource file in the source code of the SDK. The code below is the code that loads the corresponding bundle. With the macro definition below, the bundle can be loaded by the name of the bundle.

#define LOGIN_SDK_BUNDLE_NAME @ "Loginsdkresource.bundle"

#define Login_sdk_bundle_path [[[NSBundle Mainbundle] ResourcePath] Stringbyappendingpathcomponent:login_sdk_ Bundle_name]

#define Login_sdk_bundle [NSBundle Bundlewithpath:login_sdk_bundle_path]

5. Precautions :

If a resource file is referenced in the bundle project, it will appear after the project has been compiled. Storyboardc or. xibc files are not truly encapsulated successfully.

Third, the use of the Package SDK files:

1, Import the SDK, for path configuration :

After importing the SDK into our app project, we will configure it accordingly. First we'll configure the framework Search paths, which means we'll tell the compiler where our third-party SDK is located. The following configuration item is present by default when the SDK is introduced, and can be configured if it is not. The operation is as follows:

xcode--"Project --"Targets --"Build settings--"search Paths\framework Search Paths --"$ ( Project_dir)/loginsdk

2. Compile the configuration :

After configuring the path, next we will add the-OBJC and-all_load options on the other Linker flags. -OBJC This flag tells the linker to load both the Objective-c class and the category defined in the library. -all_load will force the linker to load the target file, even if there is no OBJC code. The operation is as follows:

xcode--"project--"targets--"Build settings--"linking\other Link flags--"-OBJC and-all_load

3,the use of the SDK:

After the configuration is complete, the SDK is now available in our app. The code below is our use of the above loginsdk, first obtain a singleton, and then check whether to log in, after successful login to the first page according to block callback, if not logged in, the Loginapi get login page to log in.

iOS Project feature module encapsulates SDK usage summary

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.