[ios] Look for resources in static framework bundle

The library is packaged as a static framework, so there isn’t a separate resource bundle anymore. Instead, look for the static framework inside the Frameworks folder.
This commit is contained in:
Minh Nguyễn
2015-12-22 15:05:47 -08:00
committed by Minh Nguyễn
parent f9360c3f4f
commit 26578ea9d5
2 changed files with 10 additions and 10 deletions

View File

@@ -3531,19 +3531,12 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
{
NSString *extension = imageName.pathExtension.length ? imageName.pathExtension : @"png";
NSBundle *bundle = [NSBundle mgl_frameworkBundle];
NSString *directory = nil;
if (![bundle.infoDictionary[@"CFBundlePackageType"] isEqualToString:@"FMWK"]) {
// For static libraries, the bundle is the containing application bundle
// and the resources are in a bundle alongside the static library.
directory = @"Mapbox.bundle";
}
NSString *path = [bundle pathForResource:imageName.stringByDeletingPathExtension
ofType:extension
inDirectory:directory];
ofType:extension];
if ( ! path)
{
[NSException raise:@"Resource not found" format:
@"The resource named “%@” could not be found in the Mapbox resource bundle.", imageName];
@"The resource named “%@” could not be found in the Mapbox framework bundle.", imageName];
}
return [UIImage imageWithContentsOfFile:path];

View File

@@ -8,7 +8,14 @@ void mgl_linkBundleCategory() {}
+ (instancetype)mgl_frameworkBundle
{
return [self bundleForClass:[MGLAccountManager class]];
NSBundle *bundle = [self bundleForClass:[MGLAccountManager class]];
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"]];
}
return bundle;
}
@end