小编Roc*_*che的帖子

如何在 iOS 应用中使用 swift 进行 gRPC 调用

我正在尝试使用https://github.com/grpc/grpc-swift访问一些谷歌云 RPC API

我所做的与Natural Language Example非常相似。
我能够从 master 分支获得一个使用 0.10.0 版本的版本,但是自述文件说这个分支已被弃用,应该使用“nio”分支。
不幸的是,示例代码与项目不同步,无法编译。我已尽力修复代码,但无法使其正常工作。

class NaturalLanguageRPCTests {
    let authToken : String
    var service : Google_Cloud_Language_V1_LanguageServiceServiceClient?
    var clientConnection : ClientConnection?
    let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)

    init(authToken: String) {
        self.authToken = authToken
    }

    func createService() {
        let host = "language.googleapis.com"
        let port = 443

        let tls = ClientConnection.Configuration.TLS(configuration: TLSConfiguration.forClient(applicationProtocols: ["h2"]))
        let configuration = ClientConnection.Configuration(target: .hostAndPort(host, port),
                                                           eventLoopGroup: self.eventLoopGroup,
                                                           errorDelegate: self,
                                                           connectivityStateDelegate: self,
                                                           tls: tls)
                                                           //connectionBackoff: ConnectionBackoff?)
        self.clientConnection = ClientConnection(configuration: configuration) …
Run Code Online (Sandbox Code Playgroud)

ios swift grpc

2
推荐指数
1
解决办法
1707
查看次数

标签 统计

grpc ×1

ios ×1

swift ×1