Sfoglia il codice sorgente

Add better warning for misspelled files (#11317)

* Add better warning for misspelled files

* style

* add changelog

* Update FIRApp.m
Morgan Chen 2 anni fa
parent
commit
3805752456
2 ha cambiato i file con 34 aggiunte e 0 eliminazioni
  1. 3 0
      FirebaseCore/CHANGELOG.md
  2. 31 0
      FirebaseCore/Sources/FIRApp.m

+ 3 - 0
FirebaseCore/CHANGELOG.md

@@ -1,3 +1,6 @@
+# Unreleased
+- [changed] Improved error reporting for misnamed configuration plist files (#11317).
+
 # Firebase 10.10.0
 - [changed] Firebase now requires at least Xcode 14.1.
 

+ 31 - 0
FirebaseCore/Sources/FIRApp.m

@@ -112,6 +112,9 @@ static FIRApp *sDefaultApp;
 + (void)configure {
   FIROptions *options = [FIROptions defaultOptions];
   if (!options) {
+#if DEBUG
+    [self findMisnamedGoogleServiceInfoPlist];
+#endif  // DEBUG
     [NSException raise:kFirebaseCoreErrorDomain
                 format:@"`FirebaseApp.configure()` could not find "
                        @"a valid GoogleService-Info.plist in your project. Please download one "
@@ -883,4 +886,32 @@ static FIRApp *sDefaultApp;
   }
 }
 
+#if DEBUG
++ (void)findMisnamedGoogleServiceInfoPlist {
+  for (NSBundle *bundle in [NSBundle allBundles]) {
+    // Not recursive, but we're looking for misnames, not people accidentally
+    // hiding their config file in a subdirectory of their bundle.
+    NSArray *plistPaths = [bundle pathsForResourcesOfType:@"plist" inDirectory:nil];
+    for (NSString *path in plistPaths) {
+      @autoreleasepool {
+        NSDictionary<NSString *, id> *contents = [NSDictionary dictionaryWithContentsOfFile:path];
+        if (contents == nil) {
+          continue;
+        }
+
+        NSString *projectID = contents[@"PROJECT_ID"];
+        if (projectID != nil) {
+          [NSException raise:kFirebaseCoreErrorDomain
+                      format:@"`FirebaseApp.configure()` could not find the default "
+                             @"configuration plist in your project, but did find one at "
+                             @"%@. Please rename this file to GoogleService-Info.plist to "
+                             @"use it as the default configuration.",
+                             path];
+        }
+      }
+    }
+  }
+}
+#endif  // DEBUG
+
 @end