aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Jorge Canizales <jcanizales@google.com>2015-05-17 15:22:27 -0700
committerGravatar Jorge Canizales <jcanizales@google.com>2015-05-17 16:21:51 -0700
commit05456f81c5d8ae93aed407d6503fc44136d1f6de (patch)
tree2c0fd1a8785b8d4de5453afb05ebb8f219961998 /src
parentc54a0caa0d59ee45e2f7b7e5abd4d08b2b0fad83 (diff)
Move sample app to proto3 and clarify usage example
Diffstat (limited to 'src')
-rw-r--r--src/objective-c/examples/Sample/Sample/ViewController.m37
1 files 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 c7d8e0d145..1c866babec 100644
--- a/src/objective-c/examples/Sample/Sample/ViewController.m
+++ b/src/objective-c/examples/Sample/Sample/ViewController.m
@@ -37,7 +37,8 @@
#import <gRPC/GRPCMethodName.h>
#import <gRPC/GRXWriter+Immediate.h>
#import <gRPC/GRXWriteable.h>
-#import <RemoteTest/Messages.pb.h>
+#import <RemoteTest/Messages.pbobjc.h>
+#import <RemoteTest/Test.pbrpc.h>
@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<GRXWriter> 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];