Skip to content

Commit b10b45b

Browse files
committed
Fix bundle resource loading for dynamic frameworks
1 parent 35c7840 commit b10b45b

38 files changed

+161
-91
lines changed

FirebaseAnonymousAuthUI.podspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Pod::Spec.new do |s|
99
s.platform = :ios
1010
s.ios.deployment_target = '10.0'
1111
s.ios.framework = 'UIKit'
12-
s.static_framework = true
1312
s.requires_arc = true
1413
s.cocoapods_version = '>= 1.8.0'
1514
s.pod_target_xcconfig = {
@@ -21,7 +20,7 @@ Pod::Spec.new do |s|
2120
s.dependency 'FirebaseAuthUI'
2221
s.dependency 'FirebaseAuth', '~> 8.0'
2322
s.dependency 'FirebaseCore'
24-
s.resource_bundle = {
23+
s.resource_bundles = {
2524
'FirebaseAnonymousAuthUI' => [
2625
'FirebaseAnonymousAuthUI/Sources/{Resources,Strings}/*.{png,lproj}'
2726
]

FirebaseAnonymousAuthUI/Sources/FUIAnonymousAuth.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ @implementation FUIAnonymousAuth {
4949
UIViewController *_presentingViewController;
5050
}
5151

52+
+ (NSBundle *)bundle {
53+
return [FUIAuthUtils bundleNamed:kBundleName
54+
inFrameworkBundle:[NSBundle bundleForClass:[self class]]];
55+
}
56+
5257
- (instancetype)init {
5358
return [self initWithAuthUI:[FUIAuth defaultAuthUI]];
5459
}
@@ -85,11 +90,13 @@ - (NSString *)shortName {
8590
}
8691

8792
- (NSString *)signInLabel {
88-
return FUILocalizedStringFromTableInBundle(kSignInAsGuest, kTableName, kBundleName);
93+
return FUILocalizedStringFromTableInBundle(kSignInAsGuest,
94+
kTableName,
95+
[FUIAnonymousAuth bundle]);
8996
}
9097

9198
- (UIImage *)icon {
92-
return [FUIAuthUtils imageNamed:@"ic_anonymous" fromBundleNameOrNil:kBundleName];
99+
return [FUIAuthUtils imageNamed:@"ic_anonymous" fromBundle:[FUIAnonymousAuth bundle]];
93100
}
94101

95102
- (UIColor *)buttonBackgroundColor {

FirebaseAnonymousAuthUI/Sources/Public/FirebaseAnonymousAuthUI/FUIAnonymousAuth.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ NS_ASSUME_NONNULL_BEGIN
2828
*/
2929
@property(nonatomic, readwrite) FUIButtonAlignment buttonAlignment;
3030

31+
/** @fn bundle
32+
@brief Returns the FirebaseAnonymousAuthUI resource bundle.
33+
*/
34+
+ (NSBundle *)bundle;
35+
3136
/** @fn init
3237
@brief Initialize the instance with the default AuthUI.
3338
*/

FirebaseAuthUI.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Pod::Spec.new do |s|
2121
s.dependency 'FirebaseAuth'
2222
s.dependency 'FirebaseCore'
2323
s.dependency 'GoogleUtilities/UserDefaults'
24-
s.resource_bundle = {
24+
s.resource_bundles = {
2525
'FirebaseAuthUI' => ['FirebaseAuthUI/Sources/{Resources,Strings}/*.{xib,png,lproj}']
2626
}
2727

FirebaseAuthUI/Sources/FUIAuthBaseViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil
8787

8888
- (instancetype)initWithAuthUI:(FUIAuth *)authUI {
8989
return [self initWithNibName:NSStringFromClass([self class])
90-
bundle:[FUIAuthUtils bundleNamed:FUIAuthBundleName]
90+
bundle:[FUIAuthUtils authUIBundle]
9191
authUI:authUI];
9292
}
9393

FirebaseAuthUI/Sources/FUIAuthPickerViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ @implementation FUIAuthPickerViewController {
7373

7474
- (instancetype)initWithAuthUI:(FUIAuth *)authUI {
7575
return [self initWithNibName:@"FUIAuthPickerViewController"
76-
bundle:[FUIAuthUtils bundleNamed:FUIAuthBundleName]
76+
bundle:[FUIAuthUtils authUIBundle]
7777
authUI:authUI];
7878
}
7979

FirebaseAuthUI/Sources/FUIAuthStrings.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@
130130
}
131131

132132
NSString *FUILocalizedStringFromTable(NSString *key, NSString *table) {
133-
return FUILocalizedStringFromTableInBundle(key, table, FUIAuthBundleName);
133+
return FUILocalizedStringFromTableInBundle(key, table, [FUIAuthUtils authUIBundle]);
134134
}
135135

136136
NSString *FUILocalizedStringFromTableInBundle(NSString *key,
137137
NSString *table,
138-
NSString *_Nullable bundleName) {
138+
NSBundle *_Nullable bundle) {
139139
// Don't load defaultAuthUI if the default app isn't configured. We don't recommend
140140
// people do this in our docs, but if for whatever reason they want to use a custom
141141
// app, this code shouldn't crash.
@@ -150,11 +150,10 @@
150150
}
151151
}
152152
}
153-
NSBundle *frameworkBundle = [FUIAuthUtils bundleNamed:bundleName];
154-
if (frameworkBundle == nil) {
155-
frameworkBundle = [NSBundle mainBundle];
153+
if (bundle == nil) {
154+
bundle = [NSBundle mainBundle];
156155
}
157-
return [frameworkBundle localizedStringForKey:key value:nil table:table];
156+
return [bundle localizedStringForKey:key value:nil table:table];
158157
}
159158

160159
NS_ASSUME_NONNULL_END

FirebaseAuthUI/Sources/FUIAuthUtils.m

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,50 @@
2424

2525
@implementation FUIAuthUtils
2626

27-
+ (nullable NSBundle *)bundleNamed:(nullable NSString *)bundleName {
28-
NSBundle *frameworkBundle = nil;
27+
+ (NSBundle *)authUIBundle {
28+
return [self bundleNamed:FUIAuthBundleName
29+
inFrameworkBundle:[NSBundle bundleForClass:[self class]]];
30+
}
31+
32+
+ (nullable NSBundle *)bundleNamed:(nullable NSString *)bundleName
33+
inFrameworkBundle:(nullable NSBundle *)framework {
34+
NSBundle *returnBundle = nil;
2935
if (!bundleName) {
3036
bundleName = FUIAuthBundleName;
3137
}
38+
// If using static frameworks, the bundle will be included directly in the main
39+
// bundle.
3240
NSString *path = [[NSBundle mainBundle] pathForResource:bundleName ofType:@"bundle"];
41+
42+
// Otherwise, check the appropriate framework bundle.
3343
if (!path) {
34-
// Check framework resources if bundle isn't present in main bundle.
35-
path = [[NSBundle mainBundle] pathForResource:bundleName ofType:@"framework"];
44+
NSBundle *frameworkBundle = framework;
45+
if (frameworkBundle == nil) {
46+
// If frameworkBundle is unspecified, assume main bundle/static linking.
47+
frameworkBundle = [NSBundle mainBundle];
48+
}
49+
path = [frameworkBundle pathForResource:bundleName ofType:@"bundle"];
3650
}
37-
frameworkBundle = [NSBundle bundleWithPath:path];
38-
if (!frameworkBundle) {
39-
frameworkBundle = [NSBundle bundleForClass:[self class]];
51+
if (!path) {
52+
NSLog(@"Warning: Unable to find bundle %@ in framework %@.", bundleName, framework);
4053
}
41-
return frameworkBundle;
54+
returnBundle = [NSBundle bundleWithPath:path];
55+
return returnBundle;
4256
}
4357

4458
+ (nullable UIImage *)imageNamed:(NSString *)name fromBundle:(nullable NSBundle *)bundle {
4559
if (!bundle) {
46-
bundle = [self bundleNamed:nil];
60+
bundle = [self authUIBundle];
4761
}
4862
NSString *path = [bundle pathForResource:name ofType:@"png"];
4963
if (!path) {
5064
NSLog(@"Warning: Unable to find asset %@ in bundle %@.", name, bundle);
5165
}
52-
return [UIImage imageWithContentsOfFile:path];
53-
}
54-
55-
+ (nullable UIImage *)imageNamed:(NSString *)name fromBundleNameOrNil:(nullable NSString *)bundleNameOrNil {
56-
NSString *path = [[FUIAuthUtils bundleNamed:bundleNameOrNil] pathForResource:name ofType:@"png"];
57-
if (!path) {
58-
NSLog(@"Warning: Unable to find asset %@ in bundle named %@.", name, bundleNameOrNil);
66+
if (@available(iOS 13.0, *)) {
67+
return [UIImage imageNamed:name inBundle:bundle withConfiguration:nil];
68+
} else {
69+
return [UIImage imageWithContentsOfFile:path];
5970
}
60-
return [UIImage imageWithContentsOfFile:path];
6171
}
6272

6373
@end

FirebaseAuthUI/Sources/FUIStaticContentTableViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ - (instancetype)initWithContents:(nullable FUIStaticContentTableViewContent *)co
6868
footerText:(nullable NSString *)footerText
6969
footerAction:(nullable FUIStaticContentTableViewCellAction)footerAction {
7070
if (self = [super initWithNibName:NSStringFromClass([self class])
71-
bundle:[FUIAuthUtils bundleNamed:FUIAuthBundleName]
71+
bundle:[FUIAuthUtils authUIBundle]
7272
authUI:[FUIAuth defaultAuthUI]]) {
7373
_tableViewManager.contents = contents;
7474
_nextAction = [nextAction copy];

FirebaseAuthUI/Sources/FUIStaticContentTableViewManager.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ - (void)setTableView:(nullable UITableView *)tableView {
6464
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kCellReuseIdentitfier];
6565

6666
UINib *passwordCellNib = [UINib nibWithNibName:NSStringFromClass([FUIPasswordTableViewCell class])
67-
bundle:[FUIAuthUtils bundleNamed:FUIAuthBundleName]];
67+
bundle:[FUIAuthUtils authUIBundle]];
6868
[tableView registerNib:passwordCellNib forCellReuseIdentifier:kPasswordCellReuseIdentitfier];
6969

7070
UINib *inputCellNib = [UINib nibWithNibName:NSStringFromClass([FUIInputTableViewCell class])
71-
bundle:[FUIAuthUtils bundleNamed:FUIAuthBundleName]];
71+
bundle:[FUIAuthUtils authUIBundle]];
7272
[tableView registerNib:inputCellNib forCellReuseIdentifier:kInputCellReuseIdentitfier];
7373
}
7474

0 commit comments

Comments
 (0)