|
|
|
@ -36,7 +36,7 @@ class ViewController: UIViewController { |
|
|
|
|
// Example gRPC call using a generated proto client library: |
|
|
|
|
|
|
|
|
|
let service = RMTTestService(host: RemoteHost) |
|
|
|
|
service.unaryCallWithRequest(request) { response, error in |
|
|
|
|
service.unaryCall(with: request) { response, error in |
|
|
|
|
if let response = response { |
|
|
|
|
NSLog("1. Finished successfully with response:\n\(response)") |
|
|
|
|
} else { |
|
|
|
@ -48,7 +48,7 @@ class ViewController: UIViewController { |
|
|
|
|
// Same but manipulating headers: |
|
|
|
|
|
|
|
|
|
var RPC : GRPCProtoCall! // Needed to convince Swift to capture by reference (__block) |
|
|
|
|
RPC = service.RPCToUnaryCallWithRequest(request) { response, error in |
|
|
|
|
RPC = service.rpcToUnaryCall(with: request) { response, error in |
|
|
|
|
if let response = response { |
|
|
|
|
NSLog("2. Finished successfully with response:\n\(response)") |
|
|
|
|
} else { |
|
|
|
@ -59,7 +59,7 @@ class ViewController: UIViewController { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO(jcanizales): Revert to using subscript syntax once XCode 8 is released. |
|
|
|
|
RPC.requestHeaders.setObject("My value", forKey: "My-Header") |
|
|
|
|
RPC.requestHeaders.setObject("My value", forKey: "My-Header" as NSCopying) |
|
|
|
|
|
|
|
|
|
RPC.start() |
|
|
|
|
|
|
|
|
@ -70,18 +70,18 @@ class ViewController: UIViewController { |
|
|
|
|
|
|
|
|
|
let requestsWriter = GRXWriter(value: request.data()) |
|
|
|
|
|
|
|
|
|
let call = GRPCCall(host: RemoteHost, path: method.HTTPPath, requestsWriter: requestsWriter) |
|
|
|
|
let call = GRPCCall(host: RemoteHost, path: method?.httpPath, requestsWriter: requestsWriter) |
|
|
|
|
|
|
|
|
|
call.requestHeaders.setObject("My value", forKey: "My-Header") |
|
|
|
|
call?.requestHeaders.setObject("My value", forKey: "My-Header" as NSCopying) |
|
|
|
|
|
|
|
|
|
call.startWithWriteable(GRXWriteable { response, error in |
|
|
|
|
if let response = response as? NSData { |
|
|
|
|
call?.start(with: GRXWriteable { response, error in |
|
|
|
|
if let response = response as? Data { |
|
|
|
|
NSLog("3. Received response:\n\(try! RMTSimpleResponse(data: response))") |
|
|
|
|
} else { |
|
|
|
|
NSLog("3. Finished with error: \(error!)") |
|
|
|
|
} |
|
|
|
|
NSLog("3. Response headers: \(call.responseHeaders)") |
|
|
|
|
NSLog("3. Response trailers: \(call.responseTrailers)") |
|
|
|
|
NSLog("3. Response headers: \(call?.responseHeaders)") |
|
|
|
|
NSLog("3. Response trailers: \(call?.responseTrailers)") |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|