Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.

Commit f151a1f

Browse files
authored
Merge pull request #331 from wordpress-mobile/fix/font-resource-bundle-not-found
Fix resource bundle for WordPressShared when installed from CocoaPods
2 parents 3defd5e + 623fc90 commit f151a1f

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

Sources/WordPressSharedObjC/Utility/WPFontManager.m

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ + (void)loadFontNamed:(NSString *)fontName resourceNamed:(NSString *)resourceNam
108108

109109
+ (void)loadFontResourceNamed:(NSString *)name withExtension:(NSString *)extension
110110
{
111-
#if SWIFT_PACKAGE
112-
NSBundle *bundle = SWIFTPM_MODULE_BUNDLE;
113-
#else
114-
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
115-
#endif
116-
NSURL *url = [bundle URLForResource:name withExtension:extension];
111+
NSURL *url = [[self resourceBundle] URLForResource:name withExtension:extension];
117112

118113
CFErrorRef error;
119114
if (!CTFontManagerRegisterFontsForURL((CFURLRef)url, kCTFontManagerScopeProcess, &error)) {
@@ -125,4 +120,20 @@ + (void)loadFontResourceNamed:(NSString *)name withExtension:(NSString *)extensi
125120
return;
126121
}
127122

123+
+ (NSBundle *)resourceBundle {
124+
#if SWIFT_PACKAGE
125+
return SWIFTPM_MODULE_BUNDLE;
126+
#else
127+
// When installed via CocoaPods, the resources will be bundled under `WordPressShared.bundle`.
128+
// This follows the implementation from `NSBundle+WordPressShared`.
129+
NSBundle *defaultBundle = [NSBundle bundleForClass:[self class]];
130+
NSURL *sharedBundleURL = [defaultBundle.resourceURL URLByAppendingPathComponent:@"WordPressShared.bundle"];
131+
NSBundle *sharedBundle = [NSBundle bundleWithURL:sharedBundleURL];
132+
if (sharedBundle) {
133+
return sharedBundle;
134+
}
135+
return defaultBundle;
136+
#endif
137+
}
138+
128139
@end

WordPressShared.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Pod::Spec.new do |s|
66
s.name = 'WordPressShared'
7-
s.version = '2.0.0'
7+
s.version = '2.0.1-beta.1'
88

99
s.summary = 'Shared components used in building the WordPress iOS apps and other library components.'
1010
s.description = <<-DESC

0 commit comments

Comments
 (0)