如何从iOS9连接到Postgresql [英] How to connect to postgresql from ios9
问题描述
我正在使用Swift构建iOS9.3应用程序。
I'm building iOS9.3 app with Swift.
我正在尝试直接连接PostgreSQL,是的,我知道通常最常用的方法是创建一个Web api作为应用程序和服务器之间的桥梁(例如MSSQL,PGSQL,MYSQL ...),这是一种简单/安全的方法。
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.
但是现在我需要进行直接连接,并且我已经尝试了以下几种解决方案,但是到目前为止还没有运气。
基本上这些都是从Obj-C(2010〜14)构建的,我还必须创建Bridging-Header来连接Obj-C和Swift(这不是问题)。
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。框架,PGSQLTouch,PGSQLKit-iOS-9.1.1
libpq.framework, PGSQLTouch , PGSQLKit-iOS-9.1.1
如果我只是使用 libpq,则错误不是 libpq-fe.h文件
If I just used "libpq", the error is "libpq-fe.h' file not found".
如果我使用PGSQLKit,错误将是没有这样的模块'PGClientKit_ios'事件,我设置了构建阶段,框架搜索路径。
If I used PGSQLKit the error will be "No such module 'PGClientKit_ios'" event I setup the Build Phases, Framework Search Paths.
有什么想法吗?
PGClientKit_ios的git >>> https://github.com/djthorpe/postgresql-kit
PGClientKit_ios's git>>> "https://github.com/djthorpe/postgresql-kit"
推荐答案
如果仍然有像我一样的问题,经过长时间的努力,我找到了解决方案!(我试图查找或修改所有现有的 Kits, framework)
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.
简单的步骤如下。
- 去找到一个libpq.framework。
- 您必须创建一个C类型文件(因为libpq不是Obj-c。)作为
C API进行连接libpq。 - 在那之后创建一个桥接头来连接它。(桥接不会生成自己的)
- 返回C类型文件您创建的
- 按照此 PostgreSQL C语言API教程本教程为我节省了很多时间。(C与我距离很远。)
- 如果需要,请转到Build Settings >>启用位码>>是
- 确保在设备上对其进行测试。
- 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.
完成项目后,我会将示例代码发布到git上并共享链接。
I will post the sample code on git and share the link, after I finish my project.
:)
干杯。
:) Cheers.
这篇关于如何从iOS9连接到Postgresql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!