Skip to content
This repository was archived by the owner on Aug 25, 2023. It is now read-only.

Commit b28f574

Browse files
committed
more cache response fixes based on returned error & HTTP status
1 parent 12756af commit b28f574

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎MBXMapKit.m‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,22 @@ - (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *tileData
198198
//
199199
[[self.mapView.dataSession dataTaskWithURL:[self URLForTilePath:path] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
200200
{
201-
if ( ! [response isKindOfClass:[NSHTTPURLResponse class]])
201+
if (error)
202202
{
203-
// Bail because we didn't get an HTTP response, which could be due to airplane mode.
203+
// We got an NSURLSession-level error, so let's bail with it. This also covers airplane mode.
204204
//
205-
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: NSLocalizedString(@"Non-HTTP response for tile request", nil),
206-
NSLocalizedFailureReasonErrorKey: NSLocalizedString(@"Airplane mode or another network obstacle likely exists", nil) };
205+
result(nil, error);
206+
}
207+
else if (((NSHTTPURLResponse *)response).statusCode != 200)
208+
{
209+
// We don't want to cache or use non-images, so reject any HTTP-level errors.
210+
//
211+
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"HTTP %i", ((NSHTTPURLResponse *)response).statusCode],
212+
NSLocalizedFailureReasonErrorKey: [NSHTTPURLResponse localizedStringForStatusCode:((NSHTTPURLResponse *)response).statusCode] };
207213

208214
result(nil, [NSError errorWithDomain:MBXMapKitErrorDomain code:-1 userInfo:userInfo]);
209215
}
210-
else if (data)
216+
else
211217
{
212218
// By this point, data is pretty likely to contain a valid image.
213219
//
@@ -231,12 +237,6 @@ - (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *tileData
231237
//
232238
result(data, nil);
233239
}
234-
else
235-
{
236-
// Return the fetch error directly.
237-
//
238-
result(nil, error);
239-
}
240240
}] resume];
241241
}
242242

0 commit comments

Comments
 (0)