diff --git a/examples/objective-c/route_guide/ViewControllers.m b/examples/objective-c/route_guide/ViewControllers.m index 55a193c11ae..290f7269fa2 100644 --- a/examples/objective-c/route_guide/ViewControllers.m +++ b/examples/objective-c/route_guide/ViewControllers.m @@ -206,7 +206,7 @@ static NSString * const kHostAddress = @"localhost:50051"; * database with a variable delay in between. Prints the statistics when they are sent from the * server. */ -@interface RecordRouteViewController : UIViewController +@interface RecordRouteViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *outputLabel; @@ -216,10 +216,6 @@ static NSString * const kHostAddress = @"localhost:50051"; RTGRouteGuide *_service; } -- (dispatch_queue_t)dispatchQueue { - return dispatch_get_main_queue(); -} - - (void)execRequest { NSString *dataBasePath = [NSBundle.mainBundle pathForResource:@"route_guide_db" ofType:@"json"]; @@ -234,7 +230,27 @@ static NSString * const kHostAddress = @"localhost:50051"; return; } - GRPCStreamingProtoCall *call = [_service recordRouteWithResponseHandler:self + void (^handler)(RTGRouteSummary *response, NSError *error) = ^(RTGRouteSummary *response, NSError *error) { + if (response) { + NSString *str =[NSString stringWithFormat: + @"%@\nFinished trip with %i points\nPassed %i features\n" + "Travelled %i meters\nIt took %i seconds", + self.outputLabel.text, response.pointCount, response.featureCount, + response.distance, response.elapsedTime]; + self.outputLabel.text = str; + NSLog(@"Finished trip with %i points", response.pointCount); + NSLog(@"Passed %i features", response.featureCount); + NSLog(@"Travelled %i meters", response.distance); + NSLog(@"It took %i seconds", response.elapsedTime); + } else { + NSString *str =[NSString stringWithFormat:@"%@\nRPC error: %@", self.outputLabel.text, error]; + self.outputLabel.text = str; + NSLog(@"RPC error: %@", error); + } + }; + + GRPCStreamingProtoCall *call = [_service recordRouteWithResponseHandler:[[GRPCUnaryResponseHandler alloc] initWithResponseHandler:handler + responseDispatchQueue:nil] callOptions:nil]; [call start]; for (id feature in features) { @@ -249,31 +265,6 @@ static NSString * const kHostAddress = @"localhost:50051"; [call finish]; } -- (void)didReceiveProtoMessage:(GPBMessage *)message { - RTGRouteSummary *response = (RTGRouteSummary *)message; - - if (response) { - NSString *str =[NSString stringWithFormat: - @"%@\nFinished trip with %i points\nPassed %i features\n" - "Travelled %i meters\nIt took %i seconds", - self.outputLabel.text, response.pointCount, response.featureCount, - response.distance, response.elapsedTime]; - self.outputLabel.text = str; - NSLog(@"Finished trip with %i points", response.pointCount); - NSLog(@"Passed %i features", response.featureCount); - NSLog(@"Travelled %i meters", response.distance); - NSLog(@"It took %i seconds", response.elapsedTime); - } -} - -- (void)didCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { - if (error) { - NSString *str =[NSString stringWithFormat:@"%@\nRPC error: %@", self.outputLabel.text, error]; - self.outputLabel.text = str; - NSLog(@"RPC error: %@", error); - } -} - - (void)viewDidLoad { [super viewDidLoad];