Skip to content

Commit 3805752

Browse files
authored
Add better warning for misspelled files (#11317)
* Add better warning for misspelled files * style * add changelog * Update FIRApp.m
1 parent db10be4 commit 3805752

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

FirebaseCore/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [changed] Improved error reporting for misnamed configuration plist files (#11317).
3+
14
# Firebase 10.10.0
25
- [changed] Firebase now requires at least Xcode 14.1.
36

FirebaseCore/Sources/FIRApp.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ @implementation FIRApp
112112
+ (void)configure {
113113
FIROptions *options = [FIROptions defaultOptions];
114114
if (!options) {
115+
#if DEBUG
116+
[self findMisnamedGoogleServiceInfoPlist];
117+
#endif // DEBUG
115118
[NSException raise:kFirebaseCoreErrorDomain
116119
format:@"`FirebaseApp.configure()` could not find "
117120
@"a valid GoogleService-Info.plist in your project. Please download one "
@@ -883,4 +886,32 @@ - (void)appDidBecomeActive:(NSNotification *)notification {
883886
}
884887
}
885888

889+
#if DEBUG
890+
+ (void)findMisnamedGoogleServiceInfoPlist {
891+
for (NSBundle *bundle in [NSBundle allBundles]) {
892+
// Not recursive, but we're looking for misnames, not people accidentally
893+
// hiding their config file in a subdirectory of their bundle.
894+
NSArray *plistPaths = [bundle pathsForResourcesOfType:@"plist" inDirectory:nil];
895+
for (NSString *path in plistPaths) {
896+
@autoreleasepool {
897+
NSDictionary<NSString *, id> *contents = [NSDictionary dictionaryWithContentsOfFile:path];
898+
if (contents == nil) {
899+
continue;
900+
}
901+
902+
NSString *projectID = contents[@"PROJECT_ID"];
903+
if (projectID != nil) {
904+
[NSException raise:kFirebaseCoreErrorDomain
905+
format:@"`FirebaseApp.configure()` could not find the default "
906+
@"configuration plist in your project, but did find one at "
907+
@"%@. Please rename this file to GoogleService-Info.plist to "
908+
@"use it as the default configuration.",
909+
path];
910+
}
911+
}
912+
}
913+
}
914+
}
915+
#endif // DEBUG
916+
886917
@end

0 commit comments

Comments
 (0)