2012年12月25日 星期二

[mac] PostgreSQL lib for iOS


https://devcenter.spacialdb.com/iOS.html

Git: git clone git://github.com/spacialdb/libpq-ios.git

iOS 好像不能 dynamic link libpq.5.dylib,老是噴 dyld library not loaded libpq.5.dylib 的錯誤,改拉 libpq.a 也不能動,想抓 source code 喵的直接 build libpq.a,但想到底下這句:
千萬不要搞自己。

抓現成,又有 source code 的就可以了,剛好,就那麼剛好,SpacialDB 公司剛好有提供 library for mac,雖然是兩年前的,照用,輪子能滾就好了,自己造的輪子不見得能動。

因為 Objective-C, XCode 不熟,才剛摸一天,也就是今天,怎麼加 library?直接按圖操作就好了,跑起來果然可以,舒服。

備份一下操作流程 ((測過OK)):
  1. In order to use the libpq.a in your own iOS app, simply drag and drop the libpq-ios.xcodeproj/ inside your XCode's project navigator under your current project.
  2. After that you want to add the libpq-ios as a Target Dependency in the Build Phases of our iOS app. ((XCode 畫面太豐富了,常常找不到設定要往那設))
  3. Then we add the libpq.a static library to Link it with our binary and we move the libpq.a into our Frameworks group. ((這又要找在哪裡設,就當做 XCode 操作練習吧))
  4. Finally we add the libpq headers so that we can include it inside our code. Simply right click on the Support Files group and select the Add Files to... item and select the include folder inside the root of the libpq-ios repository. Make sure you have selected the Create groups for any added folders option.
  5. Finally you can now call the libpq include file: libpq-fe.h inside your app and the project should compile without any issues.

寫 code 就請看 http://www.postgresql.org/docs/9.2/interactive/libpq-example.html,這是所謂的 test case。


最後,我得好好學 Objective-C ((http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html)),幫 stocktotal 寫個 iPhone application!

沒有留言:

張貼留言