Giter Site home page Giter Site logo

chenxing640 / ios-sdk-dev-demo Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 1.0 1.23 MB

一个简单封装的iOS SDK,提供demo及制作教程。(A simple wrapping SDK for iOS, provides demo and production tutorials.)

License: Other

Objective-C 100.00%
ios ios-sdk ios-sdk-demo lipo mach complie-sources sdk-prodution-turorials sdk mach-o library

ios-sdk-dev-demo's Introduction

如果此项目能帮助到你,就请你给一颗星。谢谢!(If this project can help you, please give it a star. Thanks!)

License MIT 

ios-sdk-dev-demo

  • 一个简单封装的iOS SDK,编写于2015年3月23日,提供demo及制作教程。

  • 目录说明

    • ExamSdk为SDK源码
    • ExamSdkDemo为集成SDK后的demo
  • 代码有点旧,勿喷!当需要制作自己的SDK时,请参考本仓库项目或者下文的制作教程

Group (ID:614799921)

Preview

  • SDK Library

  • 实现功能

Production tutorials

  1. 创建模板

①是创建.framework模板,②是创建.a模板。

  1. Project -> Target -> Build Settings 搜索 iOS Deployment Target

选择SDK的最小兼容部署,如iOS 8.0。

  1. Project -> Target -> Build Settings 搜索 Valid Architectures

目前支持的架构:真机(arm64 armv7s)、模拟器(i386 x86_64)。不用再支持armv7架构,以后也不需要支持armv7s架构。

  1. Project -> Target -> Build Settings 搜索 Mach-O Type

Mach-O Type选项有Dynamic Library, Static Library, Bundle, Executable等,选择Dynamic Library制作动态库,Static Library制作静态库,Bundle存储资源文件。

补充知识:

  • 库是共享程序代码的方式,一般分为静态库和动态库。

    • 静态库:链接时完整地拷贝至可执行文件中,被多次使用就有多份冗余拷贝。
    • 动态库:链接时不复制,程序运行时由系统动态加载到内存,供程序调用,系统只加载一次,多个程序共用,节省内存。
    • iOS里静态库形式:.a和.framework
    • iOS里动态库形式:.dylib, .tbd和.framework
  • framework为什么既有静态库又有动态库:

    • 系统的.framework是动态库,我们自己建立的.framework一般设置成静态库,也可以设置成动态库。
  • .a与.framework有什么区别:

    • .a是一个纯二进制文件,.framework中除了有二进制文件之外还有资源文件。
    • .a文件不能直接使用,至少要有.h文件配合,.framework文件可以直接使用。
    • .a + .h + sourceFile = .framework。
    • 建议用.framework.。
  • 为什么要使用静态库:

    • 方便共享代码,便于合理使用。
    • 实现iOS程序的模块化。可以把固定的业务模块化成静态库。
    • 和别人分享你的代码库,但不想让别人看到你代码的实现。
    • 开发第三方SDK的需要。
  1. Project -> Target -> Build Settings 搜索 Dead Code Stripping

在Link选项中将Dead Code Stripping改为NO (默认是YES)。确定 Dead Code(代码被定义但从未被调用)被剥离,去掉冗余的代码,即使一点冗余代码,编译后体积也是很可观的。

  1. Project -> Target -> Build Settings 搜索 Debug Information Format

在Debug Information Format选项中将DWARF with dSYM File修改成DWARF,不生成dSYM文件。

  1. Project -> Target -> Build Phases -> Complie Sources

添加要编译.h .m文件,Xcode自动将.m文件添加到Complie Sources中,同时可以使用-fno-objc-arc, fobjc-arc分别针对特定的.m文件进行MRC,ARC内存管理。

  1. Project -> Target -> Build Phases -> Headers

将工程Project要暴露的接口.h头文件拖到Public中。framework支持模块化,SDK命名尽量不要头文件重名,以便集成SDK时模块(@import xxx)不能使用。SDK资源放到一个bundle下,统一进行管理与调用。

  1. Project -> Edit Scheme -> Run -> Build Configuration

在Build Configuration选择Release,通过快捷键command+R 或者 command+B 和选择真机或模拟器输出Release版本SDK。然后在Products右击Show in Finder找到SDK。

  1. 合并库和查看库信息
  • 查看架构:使用 lipo -info 查看可执行文件(.a .framework)架构。
# For frameworks.
lipo -info ExamSimpleSdk.framework/ExamSimpleSdk

# For static libraries.
lipo -info xxx.a
  • 合并架构:使用 lipo -create 模拟器可执行文件绝对路径 真机可执行文件绝对路径 -output 输出目录/可执行文件。
# For frameworks. After the command is executed, replace the executable file in the original library.
lipo -create /Users/xxx/Library/Developer/Xcode/DerivedData/dgfkluumuexoxhcapzidtsmdgqcj/Build/Products/Release-iphonesimulator/ExamSimpleSdk.framework/ExamSimpleSdk /Users/xxx/Library/Developer/Xcode/DerivedData/dgfkluumuexoxhcapzidtsmdgqcj/Build/Products/Release-iphoneos/ExamSimpleSdk.framework/ExamSimpleSdk -output /Users/xxx/Desktop/ExamSimpleSdk 

# For static libraries. After the command is executed, replace the executable file in the original library.
lipo -create /Users/xxx/Library/Developer/Xcode/DerivedData/dgfkluumuexoxhcapzidtsmdgqcj/Build/Products/Release-iphonesimulator/xxx.a /Users/xxx/Library/Developer/Xcode/DerivedData/dgfkluumuexoxhcapzidtsmdgqcj/Build/Products/Release-iphoneos/xxx.a -output /Users/xxx/Desktop/xxx.a 
  • 移除架构
# For frameworks. After the command is executed, replace the executable file in the original library.
lipo -remove x86_64 ExamSimpleSdk.framework/ExamSimpleSdk -output ExamSimpleSdk.framework/ExamSimpleSdk

# For static libraries. After the command is executed, replace the executable file in the original library.
lipo -remove armv7s xxx.a -output xxx.a

ios-sdk-dev-demo's People

Contributors

chenxing640 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

qunios

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.