Skip to content

Commit

Permalink
Merge pull request grpc#6440 from makdharma/bugfixes
Browse files Browse the repository at this point in the history
RouteGuide example now works with moving between tabs. Fixes issue 6404.
  • Loading branch information
jcanizales committed May 9, 2016
2 parents 8f53953 + e79b08b commit dcd8d7c
Showing 1 changed file with 62 additions and 27 deletions.
89 changes: 62 additions & 27 deletions examples/objective-c/route_guide/ViewControllers.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,14 @@ + (instancetype)noteWithMessage:(NSString *)message
* Run the getFeature demo. Calls getFeature with a point known to have a feature and a point known
* not to have a feature.
*/
@interface GetFeatureViewController : UIViewController
@interface GetFeatureViewController : UIViewController {
RTGRouteGuide *service;
}
@end

@implementation GetFeatureViewController

- (void)viewDidLoad {
[super viewDidLoad];

// This only needs to be done once per host, before creating service objects for that host.
[GRPCCall useInsecureConnectionsForHost:kHostAddress];

RTGRouteGuide *service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];

- (void)execRequest {
void (^handler)(RTGFeature *response, NSError *error) = ^(RTGFeature *response, NSError *error) {
if (response.name.length) {
NSLog(@"Found feature called %@ at %@.", response.name, response.location);
Expand All @@ -111,6 +106,19 @@ - (void)viewDidLoad {
[service getFeatureWithRequest:[RTGPoint message] handler:handler];
}

- (void)viewDidLoad {
[super viewDidLoad];

// This only needs to be done once per host, before creating service objects for that host.
[GRPCCall useInsecureConnectionsForHost:kHostAddress];

service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
}

- (void)viewDidAppear:(BOOL)animated {
[self execRequest];
}

@end


Expand All @@ -120,16 +128,15 @@ - (void)viewDidLoad {
* Run the listFeatures demo. Calls listFeatures with a rectangle containing all of the features in
* the pre-generated database. Prints each response as it comes in.
*/
@interface ListFeaturesViewController : UIViewController
@interface ListFeaturesViewController : UIViewController {
RTGRouteGuide *service;
}

@end

@implementation ListFeaturesViewController

- (void)viewDidLoad {
[super viewDidLoad];

RTGRouteGuide *service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];

- (void)execRequest {
RTGRectangle *rectangle = [RTGRectangle message];
rectangle.lo.latitude = 405E6;
rectangle.lo.longitude = -750E6;
Expand All @@ -147,6 +154,16 @@ - (void)viewDidLoad {
}];
}

- (void)viewDidLoad {
[super viewDidLoad];

service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
}

- (void)viewDidAppear:(BOOL)animated {
[self execRequest];
}

@end


Expand All @@ -157,14 +174,15 @@ - (void)viewDidLoad {
* database with a variable delay in between. Prints the statistics when they are sent from the
* server.
*/
@interface RecordRouteViewController : UIViewController
@interface RecordRouteViewController : UIViewController {
RTGRouteGuide *service;
}

@end

@implementation RecordRouteViewController

- (void)viewDidLoad {
[super viewDidLoad];

- (void)execRequest {
NSString *dataBasePath = [NSBundle.mainBundle pathForResource:@"route_guide_db"
ofType:@"json"];
NSData *dataBaseContent = [NSData dataWithContentsOfFile:dataBasePath];
Expand All @@ -178,8 +196,6 @@ - (void)viewDidLoad {
return location;
}];

RTGRouteGuide *service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];

[service recordRouteWithRequestsWriter:locations
handler:^(RTGRouteSummary *response, NSError *error) {
if (response) {
Expand All @@ -193,6 +209,16 @@ - (void)viewDidLoad {
}];
}

- (void)viewDidLoad {
[super viewDidLoad];

service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
}

- (void)viewDidAppear:(BOOL)animated {
[self execRequest];
}

@end


Expand All @@ -202,14 +228,15 @@ - (void)viewDidLoad {
* Run the routeChat demo. Send some chat messages, and print any chat messages that are sent from
* the server.
*/
@interface RouteChatViewController : UIViewController
@interface RouteChatViewController : UIViewController {
RTGRouteGuide *service;
}

@end

@implementation RouteChatViewController

- (void)viewDidLoad {
[super viewDidLoad];

- (void)execRequest {
NSArray *notes = @[[RTGRouteNote noteWithMessage:@"First message" latitude:0 longitude:0],
[RTGRouteNote noteWithMessage:@"Second message" latitude:0 longitude:1],
[RTGRouteNote noteWithMessage:@"Third message" latitude:1 longitude:0],
Expand All @@ -219,8 +246,6 @@ - (void)viewDidLoad {
return note;
}];

RTGRouteGuide *service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];

[service routeChatWithRequestsWriter:notesWriter
eventHandler:^(BOOL done, RTGRouteNote *note, NSError *error) {
if (note) {
Expand All @@ -234,4 +259,14 @@ - (void)viewDidLoad {
}];
}

- (void)viewDidLoad {
[super viewDidLoad];

service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
}

- (void)viewDidAppear:(BOOL)animated {
[self execRequest];
}

@end

0 comments on commit dcd8d7c

Please sign in to comment.