From 05456f81c5d8ae93aed407d6503fc44136d1f6de Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Sun, 17 May 2015 15:22:27 -0700 Subject: [PATCH] Move sample app to proto3 and clarify usage example --- .../examples/Sample/Sample/ViewController.m | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/objective-c/examples/Sample/Sample/ViewController.m b/src/objective-c/examples/Sample/Sample/ViewController.m index c7d8e0d1454..1c866babec6 100644 --- a/src/objective-c/examples/Sample/Sample/ViewController.m +++ b/src/objective-c/examples/Sample/Sample/ViewController.m @@ -37,7 +37,8 @@ #import #import #import -#import +#import +#import @interface ViewController () @end @@ -47,18 +48,34 @@ - (void)viewDidLoad { [super viewDidLoad]; + NSString * const kRemoteHost = @"grpc-test.sandbox.google.com"; + + RMTSimpleRequest *request = [[RMTSimpleRequest alloc] init]; + request.responseSize = 10; + request.fillUsername = YES; + request.fillOauthScope = YES; + + // Example gRPC call using a generated proto client library: + + RMTTestService *service = [[RMTTestService alloc] initWithHost:kRemoteHost]; + [service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) { + if (response) { + NSLog(@"Finished successfully with response:\n%@", response); + } else if (error) { + NSLog(@"Finished with error: %@", error); + } + }]; + + + // Same example call using the generic gRPC client library: + GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:@"grpc.testing" interface:@"TestService" method:@"UnaryCall"]; - RMTSimpleRequest *request = [[[[[[RMTSimpleRequestBuilder alloc] init] - setResponseSize:100] - setFillUsername:YES] - setFillOauthScope:YES] - build]; id requestsWriter = [GRXWriter writerWithValue:[request data]]; - GRPCCall *call = [[GRPCCall alloc] initWithHost:@"grpc-test.sandbox.google.com" + GRPCCall *call = [[GRPCCall alloc] initWithHost:kRemoteHost method:method requestsWriter:requestsWriter]; @@ -66,7 +83,11 @@ RMTSimpleResponse *response = [RMTSimpleResponse parseFromData:value]; NSLog(@"Received response:\n%@", response); } completionHandler:^(NSError *errorOrNil) { - NSLog(@"Finished with error: %@", errorOrNil); + if (errorOrNil) { + NSLog(@"Finished with error: %@", errorOrNil); + } else { + NSLog(@"Finished successfully."); + } }]; [call startWithWriteable:responsesWriteable];