Update quickstart to v2 API

This commit is contained in:
Muxi Yan 2019-10-17 11:32:12 -07:00
parent b7b846bcfa
commit b45663b5c8
1 changed files with 12 additions and 10 deletions

View File

@ -200,25 +200,27 @@ class GreeterServiceImpl final : public Greeter::Service {
#### Update the client #### Update the client
Edit `examples/objective-c/helloworld/main.m` to call the new method like this: Edit the main function in `examples/objective-c/helloworld/main.m` to call the new method like this:
```c ```c
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
@autoreleasepool { @autoreleasepool {
[GRPCCall useInsecureConnectionsForHost:kHostAddress];
[GRPCCall setUserAgentPrefix:@"HelloWorld/1.0" forHost:kHostAddress];
HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress]; HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress];
HLWHelloRequest *request = [HLWHelloRequest message]; HLWHelloRequest *request = [HLWHelloRequest message];
request.name = @"Objective-C"; request.name = @"Objective-C";
[client sayHelloWithRequest:request handler:^(HLWHelloReply *response, NSError *error) { GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
NSLog(@"%@", response.message); // this example does not use TLS (secure channel); use insecure channel instead
}]; options.transport = GRPCDefaultTransportImplList.core_insecure;
[client sayHelloAgainWithRequest:request handler:^(HLWHelloReply *response, NSError *error) { options.userAgentPrefix = @"HelloWorld/1.0";
NSLog(@"%@", response.message);
}]; [[client sayHelloWithMessage:request
responseHandler:[[HLWResponseHandler alloc] init]
callOptions:options] start];
[[client sayHelloAgainWithMessage:request
responseHandler:[[HLWResponseHandler alloc] init]
callOptions:options] start];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
} }