From a1f124c39442d76af77a5aa63bba5afa4f4d6d26 Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Fri, 11 Oct 2019 15:16:12 -0400 Subject: [ios] Fix for iOS 9 crash (seen in simulator) (#15771) * [ios] Fix for iOS 9 crash (seen in simulator) * [ios] Update change log * [ios, macos] Add #if around new function. --- platform/darwin/src/MGLSDKMetricsManager.m | 28 +++++++++++++++++++++++++++- platform/ios/CHANGELOG.md | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/platform/darwin/src/MGLSDKMetricsManager.m b/platform/darwin/src/MGLSDKMetricsManager.m index 828fbcd505..0ef9ecda10 100644 --- a/platform/darwin/src/MGLSDKMetricsManager.m +++ b/platform/darwin/src/MGLSDKMetricsManager.m @@ -18,6 +18,23 @@ NSString* MGLStringFromMetricType(MGLMetricType metricType) { return eventName; } +// Taken verbatim from NXFreeArchInfo header documentation +#if TARGET_OS_IOS +static void MGLFreeArchInfo(const NXArchInfo *x) +{ + const NXArchInfo *p; + + p = NXGetAllArchInfos(); + while(p->name != NULL){ + if(x == p) + return; + p++; + } + free((char *)x->description); + free((NXArchInfo *)x); +} +#endif + @interface MGLMetricsManager() @property (strong, nonatomic) NSDictionary *metadata; @@ -54,7 +71,16 @@ NSString* MGLStringFromMetricType(MGLMetricType metricType) { if (localArchInfo) { abi = @(localArchInfo->description); - NXFreeArchInfo(localArchInfo); + + NSProcessInfo *processInfo = [NSProcessInfo processInfo]; + + // Although NXFreeArchInfo appears to be weakly linked, it does + // not have the weak_import attribute, so check the OS version. + if (&NXFreeArchInfo && [processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 0, 0}]) { + NXFreeArchInfo(localArchInfo); + } else { + MGLFreeArchInfo(localArchInfo); + } } } diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index b3eab70c60..5a7235b25a 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -22,6 +22,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Fixed an issue that cause `-[MGLMapView setCamere:withDuration:animationTimingFunction:edgePadding:completionHandler:]` persist the value of `edgePadding`. ([#15584](https://github.com/mapbox/mapbox-gl-native/pull/15584)) * Added `MGLMapView.automaticallyAdjustsContentInset` property that indicates if wether the map view should automatically adjust its content insets. ([#15584](https://github.com/mapbox/mapbox-gl-native/pull/15584)) * Fixed an issue that caused `MGLScaleBar` to have an incorrect size when resizing or rotating. ([#15703](https://github.com/mapbox/mapbox-gl-native/pull/15703)) +* Fixed crash at launch seen on iOS 9 simulator. ([#15771](https://github.com/mapbox/mapbox-gl-native/pull/15771)) ## 5.4.0 - September 25, 2019 -- cgit v1.2.1