summaryrefslogtreecommitdiff
path: root/platform/darwin/src/NSBundle+MGLAdditions.m
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-03-05 18:00:11 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-03-10 17:08:58 -0800
commite36218a8668316e8c1b0bcc06d43dad31461615c (patch)
tree04d5e58ae0c4dea4b0a50e034a8a630564cb7a53 /platform/darwin/src/NSBundle+MGLAdditions.m
parent081ee9fbefbdb37f116a5bf2c0383586bce6608a (diff)
downloadqtlocation-mapboxgl-e36218a8668316e8c1b0bcc06d43dad31461615c.tar.gz
[osx] Added OS X support for offline downloads
Diffstat (limited to 'platform/darwin/src/NSBundle+MGLAdditions.m')
-rw-r--r--platform/darwin/src/NSBundle+MGLAdditions.m40
1 files changed, 40 insertions, 0 deletions
diff --git a/platform/darwin/src/NSBundle+MGLAdditions.m b/platform/darwin/src/NSBundle+MGLAdditions.m
new file mode 100644
index 0000000000..e1f3e7c720
--- /dev/null
+++ b/platform/darwin/src/NSBundle+MGLAdditions.m
@@ -0,0 +1,40 @@
+#import "NSBundle+MGLAdditions.h"
+
+#import "MGLAccountManager.h"
+
+void mgl_linkBundleCategory() {}
+
+@implementation NSBundle (MGLAdditions)
+
++ (instancetype)mgl_frameworkBundle {
+ NSBundle *bundle = [self bundleForClass:[MGLAccountManager class]];
+ if (![bundle.infoDictionary[@"CFBundlePackageType"] isEqualToString:@"FMWK"] && !bundle.mgl_resourcesDirectory) {
+ // 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"]];
+ }
+ return bundle;
+}
+
++ (nullable NSString *)mgl_frameworkBundleIdentifier {
+ return self.mgl_frameworkInfoDictionary[@"CFBundleIdentifier"];
+}
+
++ (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;
+ }
+}
+
+- (NSString *)mgl_resourcesDirectory {
+ return [self pathForResource:@"Mapbox" ofType:@"bundle"] ? @"Mapbox.bundle" : nil;
+}
+
+@end