diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi index 3dabc19867e..d5fb6a84741 100644 --- a/gyp/platform-ios.gypi +++ b/gyp/platform-ios.gypi @@ -54,6 +54,8 @@ '../platform/ios/MGLAnnotationImage.m', '../include/mbgl/ios/MGLStyle.h', '../platform/ios/MGLStyle.mm', + '../platform/ios/MGLCategoryLoader.h', + '../platform/ios/MGLCategoryLoader.m', '../platform/ios/NSBundle+MGLAdditions.h', '../platform/ios/NSBundle+MGLAdditions.m', '../platform/ios/NSException+MGLAdditions.h', @@ -82,7 +84,6 @@ '-framework MobileCoreServices', '-framework QuartzCore', '-framework SystemConfiguration', - '-ObjC', ], }, diff --git a/platform/ios/MGLAccountManager.m b/platform/ios/MGLAccountManager.m index f7b52907674..16cd7435cda 100644 --- a/platform/ios/MGLAccountManager.m +++ b/platform/ios/MGLAccountManager.m @@ -1,5 +1,6 @@ #import "MGLAccountManager_Private.h" #import "MGLMapboxEvents.h" +#import "MGLCategoryLoader.h" #import "NSProcessInfo+MGLAdditions.h" #import @@ -34,6 +35,8 @@ + (void)load { // Can be called from any thread. // + (instancetype) sharedManager { + [MGLCategoryLoader loadCategories]; + if (NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) { return nil; } diff --git a/platform/ios/MGLCategoryLoader.h b/platform/ios/MGLCategoryLoader.h new file mode 100644 index 00000000000..874450d148a --- /dev/null +++ b/platform/ios/MGLCategoryLoader.h @@ -0,0 +1,7 @@ +#import + +@interface MGLCategoryLoader : NSObject + ++ (void)loadCategories; + +@end diff --git a/platform/ios/MGLCategoryLoader.m b/platform/ios/MGLCategoryLoader.m new file mode 100644 index 00000000000..13d82b19b2e --- /dev/null +++ b/platform/ios/MGLCategoryLoader.m @@ -0,0 +1,18 @@ +#import "MGLCategoryLoader.h" + +#import "NSBundle+MGLAdditions.h" +#import "NSProcessInfo+MGLAdditions.h" +#import "NSString+MGLAdditions.h" + +// https://github.com/mapbox/mapbox-gl-native/issues/2966 + +@implementation MGLCategoryLoader + ++ (void)loadCategories +{ + mgl_linkBundleCategory(); + mgl_linkProcessCategory(); + mgl_linkStringCategory(); +} + +@end diff --git a/platform/ios/NSBundle+MGLAdditions.h b/platform/ios/NSBundle+MGLAdditions.h index 0de96bf3105..f3800dfd953 100644 --- a/platform/ios/NSBundle+MGLAdditions.h +++ b/platform/ios/NSBundle+MGLAdditions.h @@ -2,6 +2,8 @@ NS_ASSUME_NONNULL_BEGIN +void mgl_linkBundleCategory(); + @interface NSBundle (MGLAdditions) + (NSString *)mgl_resourceBundlePath; diff --git a/platform/ios/NSBundle+MGLAdditions.m b/platform/ios/NSBundle+MGLAdditions.m index d8ba7dacc4c..3fca7384a32 100644 --- a/platform/ios/NSBundle+MGLAdditions.m +++ b/platform/ios/NSBundle+MGLAdditions.m @@ -4,6 +4,8 @@ @implementation NSBundle (MGLAdditions) +void mgl_linkBundleCategory(){} + + (NSString *)mgl_resourceBundlePath { NSString *resourceBundlePath = [[NSBundle bundleForClass:[MGLMapView class]] pathForResource:@"Mapbox" ofType:@"bundle"]; diff --git a/platform/ios/NSProcessInfo+MGLAdditions.h b/platform/ios/NSProcessInfo+MGLAdditions.h index a117f3b76d1..b97979ddb49 100644 --- a/platform/ios/NSProcessInfo+MGLAdditions.h +++ b/platform/ios/NSProcessInfo+MGLAdditions.h @@ -1,5 +1,7 @@ #import +void mgl_linkProcessCategory(); + @interface NSProcessInfo (MGLAdditions) - (BOOL)mgl_isInterfaceBuilderDesignablesAgent; diff --git a/platform/ios/NSProcessInfo+MGLAdditions.m b/platform/ios/NSProcessInfo+MGLAdditions.m index fca183c1f70..1f12f7256e1 100644 --- a/platform/ios/NSProcessInfo+MGLAdditions.m +++ b/platform/ios/NSProcessInfo+MGLAdditions.m @@ -2,6 +2,8 @@ @implementation NSProcessInfo (MGLAdditions) +void mgl_linkProcessCategory(){} + - (BOOL)mgl_isInterfaceBuilderDesignablesAgent { return [self.processName isEqualToString:@"IBDesignablesAgentCocoaTouch"]; diff --git a/platform/ios/NSString+MGLAdditions.h b/platform/ios/NSString+MGLAdditions.h index 6359576c287..a4941ac8573 100644 --- a/platform/ios/NSString+MGLAdditions.h +++ b/platform/ios/NSString+MGLAdditions.h @@ -2,6 +2,8 @@ NS_ASSUME_NONNULL_BEGIN +void mgl_linkStringCategory(); + @interface NSString (MGLAdditions) /** Returns the receiver if non-empty or nil if empty. */ diff --git a/platform/ios/NSString+MGLAdditions.m b/platform/ios/NSString+MGLAdditions.m index 969886651b0..284c63f5a94 100644 --- a/platform/ios/NSString+MGLAdditions.m +++ b/platform/ios/NSString+MGLAdditions.m @@ -2,6 +2,8 @@ @implementation NSString (MGLAdditions) +void mgl_linkStringCategory(){} + - (nullable NSString *)mgl_stringOrNilIfEmpty { return self.length ? self : nil;