From 6379cb0cd78a47697b90211df767750847369f8e Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Wed, 15 Mar 2017 16:08:29 +0200 Subject: [PATCH] [ios] Update changes in MapObserver::onDidFailLoadingMap --- platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLMapView.mm | 52 +++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index e59e02c87..a2b5d9ed7 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -55,6 +55,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Fixed an issue that was causing the system location indicator to stay on in background after telemetry was disabled. ([#7833](https://github.com/mapbox/mapbox-gl-native/pull/7833)) * Added support for predicates in rendered feature querying [8256](https://github.com/mapbox/mapbox-gl-native/pull/8246) * Added a nightly build of the dynamic framework. ([#8337](https://github.com/mapbox/mapbox-gl-native/pull/8337)) +* Improved the error message when the map fails to load. [8418](https://github.com/mapbox/mapbox-gl-native/pull/8418) ## 3.4.2 - February 21, 2017 diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 7aef71cdd..6e4571444 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #import "Mapbox.h" #import "MGLFeature_Private.h" @@ -4794,7 +4796,7 @@ public: } } -- (void)willStartLoadingMap { +- (void)mapViewWillStartLoadingMap { if (!_mbglMap) { return; } @@ -4805,7 +4807,7 @@ public: } } -- (void)didFinishLoadingMap { +- (void)mapViewDidFinishLoadingMap { if (!_mbglMap) { return; } @@ -4820,19 +4822,18 @@ public: } } -- (void)didFailLoadingMap { +- (void)mapViewDidFailLoadingMapWithError:(NSError *)error { if (!_mbglMap) { return; } if ([self.delegate respondsToSelector:@selector(mapViewDidFailLoadingMap:withError:)]) { - NSError *error = [NSError errorWithDomain:MGLErrorDomain code:0 userInfo:nil]; [self.delegate mapViewDidFailLoadingMap:self withError:error]; } } -- (void)willStartRenderingFrame { +- (void)mapViewWillStartRenderingFrame { if (!_mbglMap) { return; } @@ -4843,7 +4844,7 @@ public: } } -- (void)didFinishRenderingFrameFullyRendered:(BOOL)fullyRendered { +- (void)mapViewDidFinishRenderingFrameFullyRendered:(BOOL)fullyRendered { if (!_mbglMap) { return; } @@ -4861,7 +4862,7 @@ public: } } -- (void)willStartRenderingMap { +- (void)mapViewWillStartRenderingMap { if (!_mbglMap) { return; } @@ -4872,7 +4873,7 @@ public: } } -- (void)didFinishRenderingMapFullyRendered:(BOOL)fullyRendered { +- (void)mapViewDidFinishRenderingMapFullyRendered:(BOOL)fullyRendered { if (!_mbglMap) { return; } @@ -5375,33 +5376,52 @@ public: } void onWillStartLoadingMap() override { - [nativeView willStartLoadingMap]; + [nativeView mapViewWillStartLoadingMap]; } void onDidFinishLoadingMap() override { - [nativeView didFinishLoadingMap]; + [nativeView mapViewDidFinishLoadingMap]; } - void onDidFailLoadingMap() override { - [nativeView didFailLoadingMap]; + void onDidFailLoadingMap(std::exception_ptr exception) override { + NSString *description; + MGLErrorCode code; + try { + std::rethrow_exception(exception); + } catch (const mbgl::util::StyleParseException&) { + code = MGLErrorCodeParseStyleFailed; + description = NSLocalizedStringWithDefaultValue(@"PARSE_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style is corrupted.", @""); + } catch (const mbgl::util::StyleLoadException&) { + code = MGLErrorCodeLoadStyleFailed; + description = NSLocalizedStringWithDefaultValue(@"PARSE_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style can't be loaded.", @""); + } catch (const mbgl::util::NotFoundException&) { + code = MGLErrorCodeNotFound; + description = NSLocalizedStringWithDefaultValue(@"LOAD_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style can’t be found or is incompatible.", @""); + } catch (...) { + code = MGLErrorCodeUnknown; + description = NSLocalizedStringWithDefaultValue(@"LOAD_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because an unknown error occurred.", @""); + } + NSDictionary *userInfo = @{NSLocalizedDescriptionKey:description, NSLocalizedFailureReasonErrorKey:@(mbgl::util::toString(exception).c_str())}; + NSError *error = [NSError errorWithDomain:MGLErrorDomain code:code userInfo:userInfo]; + [nativeView mapViewDidFailLoadingMapWithError:error]; } void onWillStartRenderingFrame() override { - [nativeView willStartRenderingFrame]; + [nativeView mapViewWillStartRenderingFrame]; } void onDidFinishRenderingFrame(mbgl::MapObserver::RenderMode mode) override { bool fullyRendered = mode == mbgl::MapObserver::RenderMode::Full; - [nativeView didFinishRenderingFrameFullyRendered:fullyRendered]; + [nativeView mapViewDidFinishRenderingFrameFullyRendered:fullyRendered]; } void onWillStartRenderingMap() override { - [nativeView willStartRenderingMap]; + [nativeView mapViewWillStartRenderingMap]; } void onDidFinishRenderingMap(mbgl::MapObserver::RenderMode mode) override { bool fullyRendered = mode == mbgl::MapObserver::RenderMode::Full; - [nativeView didFinishRenderingMapFullyRendered:fullyRendered]; + [nativeView mapViewDidFinishRenderingMapFullyRendered:fullyRendered]; } void onDidFinishLoadingStyle() override {