Xcode4.6创建和使用iOS的dylib动态库

来源:互联网 发布:密度聚类算法 编辑:程序博客网 时间:2024/05/21 17:51

转载请注明出处:http://blog.csdn.net/hursing

此为xcode4的方法,xcode3的方法请查看 Xcode3创建和使用iOS的dylib动态库


找到两个目录,最好用两个finder窗口分别打开:

目录一:

[plain] view plaincopy
  1. /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications/  

目录二:

[plain] view plaincopy
  1. /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications/  

(这里只说iOS真机版,模拟器版类似,/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform)

把目录一下的iPhoneOSPackageTypes.xcspec和iPhoneOSProductTypes.xcspec拷贝到桌面(或者其它有写权限的地方),分别用xcode打开。

再用xcode打开目录二下的MacOSX Package Types.xcspec和MacOSX Product Types.xcspec

把MacOSX Package Types.xcspec中Identifier为com.apple.package-type.mach-o-dylib的item拖到iPhoneOSPackageTypes.xcspec,令iPhoneOSPackageTypes.xcspec变成:


把MacOSX Product Types.xcspec中Identifier为com.apple.product-type.library.dynamic的item拖到iPhoneOSProductTypes.xcspec,令iPhoneOSProductTypes.xcspec变成:


保存修改,把iPhoneOSPackageTypes.xcspec和iPhoneOSProductTypes.xcspec拷贝回去目录一,此时会因为没有写权限而提示需要鉴定,输入密码即可。


创建工程模板:

[plain] view plaincopy
  1. /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Framework & Library/Cocoa Touch Static Library.xctemplate  

把以上整个文件夹复制到桌面,文件夹改名为Cocoa Touch Dynamic Library.xctemplate,用xcode打开里面的TemplateInfo.plist,修改三个地方:


保存,然后把Cocoa Touch Dynamic Library.xctemplate拷贝回去

[plain] view plaincopy
  1. /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Framework & Library/  

这时又需要鉴定。

重启xcode,就能看到:



随便创建一个app工程和一个dylib工程,做好编译依赖以及copy dylib to bundle。(点击查看大图)


动态库的工程要设置安装目录:(点击查看大图)



demo/sample和已经改好的模板 下载地址:http://download.csdn.net/detail/hursing/5416617

安装好app后,运行。然后修改UIAlertView的message,编译,用各种工具(我在Mac上用的是iPhone Explorer)把新的dylib覆盖旧的,重启程序,message成功改变! 验证ok。

以上是直接链接静态库的方法,也可以用dyld函数动态加载。要把dylib放在Document文件夹内的话,修改安装目录即可,第一次启动要自己copy出去哦。


原创粉丝点击