標籤:c class blog code a http
此為xcode4的方法,xcode3的方法請查看 Xcode3建立和使用iOS的dylib動態庫
找到兩個目錄,最好用兩個finder視窗分別開啟:
目錄一:
[plain] view plaincopy
- /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications/
目錄二:
[plain] view plaincopy
- /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
- /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
- /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出去哦。
轉自: http://blog.csdn.net/hursing/article/details/8951958