aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/objective-c/route_guide/ViewControllers.m
diff options
context:
space:
mode:
Diffstat (limited to 'examples/objective-c/route_guide/ViewControllers.m')
-rw-r--r--examples/objective-c/route_guide/ViewControllers.m41
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/objective-c/route_guide/ViewControllers.m b/examples/objective-c/route_guide/ViewControllers.m
index e32978240b..b916a4ee0c 100644
--- a/examples/objective-c/route_guide/ViewControllers.m
+++ b/examples/objective-c/route_guide/ViewControllers.m
@@ -83,6 +83,7 @@ static NSString * const kHostAddress = @"localhost:50051";
@interface GetFeatureViewController : UIViewController {
RTGRouteGuide *service;
}
+@property (weak, nonatomic) IBOutlet UILabel *output_label;
@end
@implementation GetFeatureViewController
@@ -90,10 +91,16 @@ static NSString * const kHostAddress = @"localhost:50051";
- (void)execRequest {
void (^handler)(RTGFeature *response, NSError *error) = ^(RTGFeature *response, NSError *error) {
if (response.name.length) {
+ NSString *str =[NSString stringWithFormat:@"%@\nFound feature called %@ at %@.", self.output_label.text, response.location, response.name];
+ self.output_label.text = str;
NSLog(@"Found feature called %@ at %@.", response.name, response.location);
} else if (response) {
+ NSString *str =[NSString stringWithFormat:@"%@\nFound no features at %@", self.output_label.text,response.location];
+ self.output_label.text = str;
NSLog(@"Found no features at %@", response.location);
} else {
+ NSString *str =[NSString stringWithFormat:@"%@\nRPC error: %@", self.output_label.text, error];
+ self.output_label.text = str;
NSLog(@"RPC error: %@", error);
}
};
@@ -116,6 +123,9 @@ static NSString * const kHostAddress = @"localhost:50051";
}
- (void)viewDidAppear:(BOOL)animated {
+ self.output_label.text = @"RPC log:";
+ self.output_label.numberOfLines = 0;
+ self.output_label.font = [UIFont fontWithName:@"Helvetica Neue" size:8.0];
[self execRequest];
}
@@ -131,6 +141,7 @@ static NSString * const kHostAddress = @"localhost:50051";
@interface ListFeaturesViewController : UIViewController {
RTGRouteGuide *service;
}
+@property (weak, nonatomic) IBOutlet UILabel *output_label;
@end
@@ -147,8 +158,12 @@ static NSString * const kHostAddress = @"localhost:50051";
[service listFeaturesWithRequest:rectangle
eventHandler:^(BOOL done, RTGFeature *response, NSError *error) {
if (response) {
+ NSString *str =[NSString stringWithFormat:@"%@\nFound feature at %@ called %@.", self.output_label.text, response.location, response.name];
+ self.output_label.text = str;
NSLog(@"Found feature at %@ called %@.", response.location, response.name);
} else if (error) {
+ NSString *str =[NSString stringWithFormat:@"%@\nRPC error: %@", self.output_label.text, error];
+ self.output_label.text = str;
NSLog(@"RPC error: %@", error);
}
}];
@@ -161,6 +176,9 @@ static NSString * const kHostAddress = @"localhost:50051";
}
- (void)viewDidAppear:(BOOL)animated {
+ self.output_label.text = @"RPC log:";
+ self.output_label.numberOfLines = 0;
+ self.output_label.font = [UIFont fontWithName:@"Helvetica Neue" size:8.0];
[self execRequest];
}
@@ -177,6 +195,7 @@ static NSString * const kHostAddress = @"localhost:50051";
@interface RecordRouteViewController : UIViewController {
RTGRouteGuide *service;
}
+@property (weak, nonatomic) IBOutlet UILabel *output_label;
@end
@@ -192,6 +211,8 @@ static NSString * const kHostAddress = @"localhost:50051";
RTGPoint *location = [RTGPoint message];
location.longitude = [((NSNumber *) feature[@"location"][@"longitude"]) intValue];
location.latitude = [((NSNumber *) feature[@"location"][@"latitude"]) intValue];
+ NSString *str =[NSString stringWithFormat:@"%@\nVisiting point %@", self.output_label.text, location];
+ self.output_label.text = str;
NSLog(@"Visiting point %@", location);
return location;
}];
@@ -199,11 +220,19 @@ static NSString * const kHostAddress = @"localhost:50051";
[service recordRouteWithRequestsWriter:locations
handler:^(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.output_label.text, response.pointCount, response.featureCount,
+ response.distance, response.elapsedTime];
+ self.output_label.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.output_label.text, error];
+ self.output_label.text = str;
NSLog(@"RPC error: %@", error);
}
}];
@@ -216,6 +245,9 @@ static NSString * const kHostAddress = @"localhost:50051";
}
- (void)viewDidAppear:(BOOL)animated {
+ self.output_label.text = @"RPC log:";
+ self.output_label.numberOfLines = 0;
+ self.output_label.font = [UIFont fontWithName:@"Helvetica Neue" size:8.0];
[self execRequest];
}
@@ -231,6 +263,7 @@ static NSString * const kHostAddress = @"localhost:50051";
@interface RouteChatViewController : UIViewController {
RTGRouteGuide *service;
}
+@property (weak, nonatomic) IBOutlet UILabel *output_label;
@end
@@ -249,8 +282,13 @@ static NSString * const kHostAddress = @"localhost:50051";
[service routeChatWithRequestsWriter:notesWriter
eventHandler:^(BOOL done, RTGRouteNote *note, NSError *error) {
if (note) {
+ NSString *str =[NSString stringWithFormat:@"%@\nGot message %@ at %@",
+ self.output_label.text, note.message, note.location];
+ self.output_label.text = str;
NSLog(@"Got message %@ at %@", note.message, note.location);
} else if (error) {
+ NSString *str =[NSString stringWithFormat:@"%@\nRPC error: %@", self.output_label.text, error];
+ self.output_label.text = str;
NSLog(@"RPC error: %@", error);
}
if (done) {
@@ -266,6 +304,9 @@ static NSString * const kHostAddress = @"localhost:50051";
}
- (void)viewDidAppear:(BOOL)animated {
+ self.output_label.text = @"RPC log:";
+ self.output_label.numberOfLines = 0;
+ self.output_label.font = [UIFont fontWithName:@"Helvetica Neue" size:8.0];
[self execRequest];
}