如何从iOS连接到本地Google App Engine端点?

时间:2014-09-08 12:23:19

标签: ios objective-c google-app-engine google-api google-cloud-endpoints

我们有一个需要连接到Google App Engine端点的iOS应用。 该连接通过Objective-C Google Api和App Engine端点发现文件中生成的API完成。

该代码可以很好地连接到appspot.com部署的应用程序,但我们无法管理运行相同应用程序的本地App Engine服务器。

调用端点的代码是(Swift代码):

let myService =  GTLServiceMyService()
self.myService.authorizer = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName(kKeychainItemName,
        clientID: kClientID,
        clientSecret: kClientSecret)
let query = GTLQueryMyService.queryForContentsGetContents() as GTLQueryMyService
query.orderBy = "NAME"
self.myService.executeQuery(query, completionHandler: { (ticket: GTLServiceTicket!, object: AnyObject!, error: NSError!) -> Void in
    // Process the response
})

正如我所说,代码正在运行,但只有appspot.com服务器,如何连接到本地服务器api?

http://localhost:8080/_ah/api

另一个Objective-C例子对我们有好处。

谢谢你

2 个答案:

答案 0 :(得分:2)

只是为了帮助任何有同样问题的人解决方案是在authorizer上设置myService对象之后放置此代码(使用Swift):

    (self.myService.authorizer as GTMOAuth2Authentication).shouldAuthorizeAllRequests = true
    self.myService.retryEnabled = true
    self.myService.fetcherService.allowLocalhostRequest = true
    self.myService.rpcURL = NSURL(string: "http://localhost:8080/_ah/api/rpc?prettyPrint=false")
    self.myService.apiVersion = "v1"

答案 1 :(得分:0)

关于你的问题"正如我所说,代码正在运行,但只有appspot.com服务器,如何连接到本地服务器api? "

请记住,手机上的localhost是指手机的本地主机,它与您的开发机器的本地主机不同。 Localhost解析为IP地址127.0.0.1(通常)。因此,要连接到本地运行的应用引擎实例,您需要在本地网络上使用该计算机的IP地址。