Skip to content

Commit f0f172e

Browse files
authored
Merge pull request #959 from firebase/firebase-8
Fix bundle resource loading for dynamic frameworks
2 parents 8797fa7 + e9f4eae commit f0f172e

File tree

44 files changed

+172
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+172
-116
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/FirebaseAnonymousAuthUITests/FirebaseAnonymousAuthUITests.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ @implementation FirebaseAnonymousAuthUITests
3030

3131
- (void)setUp {
3232
[super setUp];
33-
34-
id mockUtilsClass = OCMClassMock([FUIAuthUtils class]);
35-
OCMStub(ClassMethod([mockUtilsClass bundleNamed:OCMOCK_ANY])).
36-
andReturn([NSBundle bundleForClass:[FUIAnonymousAuth class]]);
3733

3834
id authUIClass = OCMClassMock([FUIAuth class]);
3935
OCMStub(ClassMethod([authUIClass authUIWithAuth:OCMOCK_ANY])).

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: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,53 @@
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+
// Use the main bundle as a default if the framework wasn't provided.
39+
NSBundle *frameworkBundle = framework;
40+
if (frameworkBundle == nil) {
41+
// If frameworkBundle is unspecified, assume main bundle/static linking.
42+
frameworkBundle = [NSBundle mainBundle];
43+
}
44+
// If using static frameworks, the bundle will be included directly in the main
45+
// bundle.
3246
NSString *path = [[NSBundle mainBundle] pathForResource:bundleName ofType:@"bundle"];
47+
48+
// Otherwise, check the appropriate framework bundle.
3349
if (!path) {
34-
// Check framework resources if bundle isn't present in main bundle.
35-
path = [[NSBundle mainBundle] pathForResource:bundleName ofType:@"framework"];
50+
path = [frameworkBundle pathForResource:bundleName ofType:@"bundle"];
3651
}
37-
frameworkBundle = [NSBundle bundleWithPath:path];
38-
if (!frameworkBundle) {
39-
frameworkBundle = [NSBundle bundleForClass:[self class]];
52+
if (!path) {
53+
NSLog(@"Warning: Unable to find bundle %@ in framework %@.", bundleName, framework);
54+
// Fall back on the root module.
55+
return frameworkBundle;
4056
}
41-
return frameworkBundle;
57+
returnBundle = [NSBundle bundleWithPath:path];
58+
return returnBundle;
4259
}
4360

4461
+ (nullable UIImage *)imageNamed:(NSString *)name fromBundle:(nullable NSBundle *)bundle {
4562
if (!bundle) {
46-
bundle = [self bundleNamed:nil];
63+
bundle = [self authUIBundle];
4764
}
4865
NSString *path = [bundle pathForResource:name ofType:@"png"];
4966
if (!path) {
5067
NSLog(@"Warning: Unable to find asset %@ in bundle %@.", name, bundle);
5168
}
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);
69+
if (@available(iOS 13.0, *)) {
70+
return [UIImage imageNamed:name inBundle:bundle withConfiguration:nil];
71+
} else {
72+
return [UIImage imageWithContentsOfFile:path];
5973
}
60-
return [UIImage imageWithContentsOfFile:path];
6174
}
6275

6376
@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];

0 commit comments

Comments
 (0)