Skip to content

Commit

Permalink
some more error checking before using gogo response
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpk committed Jan 29, 2019
1 parent 0eff7f6 commit d930600
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions GPSLogger/GLManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -1251,26 +1251,35 @@ - (void)retrieveCurrentFlightData {
_stoppedFromInFlightTracker = YES;
[self disableTracking];

// Record this data point
NSDictionary *info = [[responseObject objectForKey:@"Response"] objectForKey:@"flightInfo"];

_currentFlightSummary = [NSString stringWithFormat:@"%@ %@ to %@\nTail number %@",
[info valueForKey:@"flightNumberInfo"],
[info valueForKey:@"departureAirportCodeIata"],
[info valueForKey:@"destinationAirportCodeIata"],
[info valueForKey:@"tailNumber"]
];

// Create a fake datapoint for the UI to grab
CLLocation *loc = [self currentLocationFromGogoDictionary:info];

self.lastLocation = loc;
self.lastLocationDictionary = [self currentDictionaryFromGogoDictionary:info];
_lastMotionString = @"flying";

[self writeCurrentLocationToHistory];

self.currentTripMode = @"plane";
if([responseObject objectForKey:@"Response"] != nil) {

// Record this data point
NSDictionary *info = [[responseObject objectForKey:@"Response"] objectForKey:@"flightInfo"];

if(info != nil) {
_currentFlightSummary = [NSString stringWithFormat:@"%@ %@ to %@\nTail number %@",
[info valueForKey:@"flightNumberInfo"],
[info valueForKey:@"departureAirportCodeIata"],
[info valueForKey:@"destinationAirportCodeIata"],
[info valueForKey:@"tailNumber"]
];

// Create a fake datapoint for the UI to grab
CLLocation *loc = [self currentLocationFromGogoDictionary:info];

self.lastLocation = loc;
self.lastLocationDictionary = [self currentDictionaryFromGogoDictionary:info];
_lastMotionString = @"flying";

[self writeCurrentLocationToHistory];

self.currentTripMode = @"plane";
} else {
// No flight info returned, plane may have landed
}
} else {
// Gogo returned non flight info, maybe an error
}

// Start a new timer to check again
[self startFlightTrackerTimer];
Expand Down

0 comments on commit d930600

Please sign in to comment.