I'm building iOS9.3 app with Swift.
I'm trying to connect the PostgreSQL directly, and yes I know usually the most common approach is to create a web api as bridge between apps and server(like MSSQL,PGSQL,MYSQL...), and that is the easy/safe way to do it.
But right now I need to do direct connection, and I already tried several solution as below, but so far there is no luck. Basically these are build from Obj-C(2010~14), and I also have to create Bridging-Header to connect Obj-C and Swift(That is not a problem).
But I'm stuck here. :(
libpq.framework, PGSQLTouch , PGSQLKit-iOS-9.1.1
If I just used "libpq", the error is "libpq-fe.h' file not found".
If I used PGSQLKit the error will be "No such module 'PGClientKit_ios'" event I setup the Build Phases, Framework Search Paths.
have any ideas?
PGClientKit_ios's git>>> "https://github.com/djthorpe/postgresql-kit"
if anyone still having the same issue like I did, after a long struggled I got a solution!(I was trying to find or modified all kind of the existing "Kits","framework")
I was surprised, what I was looking for, could be so rarely, suddenly very envious those android developer.
The simple step as follow.
- Go find a libpq.framework.
- You have to create a C type file(because libpq is not Obj-c.) as C API to connect libpq.
- After that create a Bridging-Header to connect it.(It Bridging will not generate its own)
- Back to the C type file you created
- Follow this "PostgreSQL C Language API" tutorial this tutorial saved me a lot of time .(C has been a very far away from me.)
- If need, go to Build Settings >> Enable Bitcode >> YES
- Make sure test it on the device.
I will post the sample code on git and share the link, after I finish my project.
:) Cheers.
来源:https://stackoverflow.com/questions/37987977/how-to-connect-to-postgresql-from-ios9