summaryrefslogtreecommitdiff
path: root/platform/darwin/src/NSBundle+MGLAdditions.m
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/NSBundle+MGLAdditions.m')
-rw-r--r--platform/darwin/src/NSBundle+MGLAdditions.m33
1 files changed, 19 insertions, 14 deletions
diff --git a/platform/darwin/src/NSBundle+MGLAdditions.m b/platform/darwin/src/NSBundle+MGLAdditions.m
index 76d9cc0db7..f383a50300 100644
--- a/platform/darwin/src/NSBundle+MGLAdditions.m
+++ b/platform/darwin/src/NSBundle+MGLAdditions.m
@@ -6,12 +6,19 @@
+ (instancetype)mgl_frameworkBundle {
NSBundle *bundle = [self bundleForClass:[MGLAccountManager class]];
- if (![bundle.infoDictionary[@"CFBundlePackageType"] isEqualToString:@"FMWK"] && !bundle.mgl_resourcesDirectory) {
+
+ if (![bundle.infoDictionary[@"CFBundlePackageType"] isEqualToString:@"FMWK"]) {
// For static frameworks, the bundle is the containing application
- // bundle but the resources are still in the framework bundle.
- bundle = [NSBundle bundleWithPath:[bundle.privateFrameworksPath
- stringByAppendingPathComponent:@"Mapbox.framework"]];
+ // bundle but the resources are in Mapbox.bundle.
+ NSString *bundlePath = [bundle pathForResource:@"Mapbox" ofType:@"bundle"];
+ if (bundlePath) {
+ bundle = [self bundleWithPath:bundlePath];
+ } else {
+ [NSException raise:@"MGLBundleNotFoundException" format:
+ @"The Mapbox framework bundle could not be found. If using the Mapbox iOS SDK as a static framework, make sure that Mapbox.bundle is copied into the root of the app bundle."];
+ }
}
+
return bundle;
}
@@ -21,18 +28,16 @@
+ (nullable NS_DICTIONARY_OF(NSString *, id) *)mgl_frameworkInfoDictionary {
NSBundle *bundle = self.mgl_frameworkBundle;
- if (bundle.mgl_resourcesDirectory) {
- NSString *infoPlistPath = [bundle pathForResource:@"Info"
- ofType:@"plist"
- inDirectory:bundle.mgl_resourcesDirectory];
- return [NSDictionary dictionaryWithContentsOfFile:infoPlistPath];
- } else {
- return bundle.infoDictionary;
- }
+ return bundle.infoDictionary;
}
-- (NSString *)mgl_resourcesDirectory {
- return [self pathForResource:@"Mapbox" ofType:@"bundle"] ? @"Mapbox.bundle" : nil;
++ (nullable NSString *)mgl_applicationBundleIdentifier {
+ NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
+ if (!bundleIdentifier) {
+ // There’s no main bundle identifier when running in a unit test bundle.
+ bundleIdentifier = [NSBundle bundleForClass:[MGLAccountManager class]].bundleIdentifier;
+ }
+ return bundleIdentifier;
}
@end