summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2016-09-27 23:24:44 -0700
committerJesse Bounds <jesse@rebounds.net>2016-09-28 09:44:19 -0700
commit9a41b8abaf75a344bd86d55878ee87179eb63d95 (patch)
tree6cc8377c493dc3ab976155e0bb6628e45d5ab3a2
parentb1518944a732138f5ed2eafc69fe794143a4af62 (diff)
downloadqtlocation-mapboxgl-9a41b8abaf75a344bd86d55878ee87179eb63d95.tar.gz
[ios, macos] Guard against nil bundle identifier during tests
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm13
1 files changed, 11 insertions, 2 deletions
diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm
index dab870ea3b..f279235ca0 100644
--- a/platform/darwin/src/MGLOfflineStorage.mm
+++ b/platform/darwin/src/MGLOfflineStorage.mm
@@ -59,7 +59,7 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
appropriateForURL:nil
create:YES
error:nil];
- NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
+ NSString *bundleIdentifier = [self bundleIdentifier];
if (!bundleIdentifier) {
// There’s no main bundle identifier when running in a unit test bundle.
bundleIdentifier = [NSBundle bundleForClass:self].bundleIdentifier;
@@ -93,7 +93,7 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
NSString *legacyCachePath = [legacyPaths.firstObject stringByAppendingPathComponent:MGLOfflineStorageFileName3_2_0_beta_1];
#elif TARGET_OS_MAC
// ~/Library/Caches/tld.app.bundle.id/offline.db
- NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
+ NSString *bundleIdentifier = [self bundleIdentifier];
NSURL *legacyCacheDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
@@ -137,6 +137,15 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
return self;
}
++ (NSString *)bundleIdentifier {
+ NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
+ if (!bundleIdentifier) {
+ // There’s no main bundle identifier when running in a unit test bundle.
+ bundleIdentifier = [NSBundle bundleForClass:self].bundleIdentifier;
+ }
+ return bundleIdentifier;
+}
+
- (void)dealloc {
[[MGLAccountManager sharedManager] removeObserver:self forKeyPath:@"accessToken"];