Ver código fonte

FIS: IID incompatible version exception. (#4258)

* FIS: IID incompatible version exception.

* FirebaseInstallations.podspec: set preprocessor flags based on env vars.

* FIS Travis: set required env vars

* /scripts/style.sh

* FIS: FIRInstantiationTimingEagerInDefaultApp

* FIS: FIRInstantiationTimingAlwaysEager
Maksym Malyhin 6 anos atrás
pai
commit
f6e1eea53c

+ 6 - 0
.travis.yml

@@ -671,6 +671,8 @@ jobs:
     - stage: test
       env:
         - PROJECT=Installations PLATFORM=iOS METHOD=pod-lib-lint
+        - FIS_ALLOWS_INCOMPATIBLE_IID_VERSION=1
+        - FIS_INTEGRATION_TESTS_REQUIRED=1
       before_install:
         - ./scripts/if_changed.sh ./scripts/install_prereqs.sh
       script:
@@ -681,6 +683,8 @@ jobs:
     - stage: test
       env:
         - PROJECT=Installations PLATFORM=macOS METHOD=pod-lib-lint
+        - FIS_ALLOWS_INCOMPATIBLE_IID_VERSION=1
+        - FIS_INTEGRATION_TESTS_REQUIRED=1
       before_install:
         - ./scripts/if_changed.sh ./scripts/install_prereqs.sh
       script:
@@ -691,6 +695,8 @@ jobs:
     - stage: test
       env:
         - PROJECT=Installations PLATFORM=tvOS METHOD=pod-lib-lint
+        - FIS_ALLOWS_INCOMPATIBLE_IID_VERSION=1
+        - FIS_INTEGRATION_TESTS_REQUIRED=1
       before_install:
         - ./scripts/if_changed.sh ./scripts/install_prereqs.sh
       script:

+ 62 - 53
FirebaseInstallations.podspec

@@ -1,59 +1,68 @@
 Pod::Spec.new do |s|
-    s.name             = 'FirebaseInstallations'
-    s.version          = '0.1.0'
-    s.summary          = 'Firebase Installations for iOS'
-
-    s.description      = <<-DESC
-    Firebase Installations for iOS.
-                         DESC
-
-    s.homepage         = 'https://firebase.google.com'
-    s.license          = { :type => 'Apache', :file => 'LICENSE' }
-    s.authors          = 'Google, Inc.'
-
-    s.source           = {
-      :git => 'https://github.com/firebase/firebase-ios-sdk.git',
-      :tag => 'Installations-' + s.version.to_s
-    }
-    s.social_media_url = 'https://twitter.com/Firebase'
-    s.ios.deployment_target = '8.0'
-    s.osx.deployment_target = '10.11'
-    s.tvos.deployment_target = '10.0'
-
-    s.cocoapods_version = '>= 1.4.0'
-    s.static_framework = true
-    s.prefix_header_file = false
-
-    base_dir = "FirebaseInstallations/Source/"
-    s.source_files = base_dir + 'Library/**/*.[mh]'
-    s.public_header_files = base_dir + 'Library/Public/*.h'
-    s.pod_target_xcconfig = {
-      'GCC_C_LANGUAGE_STANDARD' => 'c99',
-      'GCC_PREPROCESSOR_DEFINITIONS' =>
-        'FIRInstallations_LIB_VERSION=' + String(s.version)
-    }
-    s.framework = 'Security'
-    s.dependency 'FirebaseCore', '~> 6.0'
-    s.dependency 'PromisesObjC', '~> 1.2'
-    s.dependency 'GoogleUtilities/UserDefaults', '~> 6.2'
-
-    s.test_spec 'unit' do |unit_tests|
-      unit_tests.source_files = base_dir + 'Tests/Unit/**/*.[mh]',
-                                base_dir + 'Tests/Utils/**/*.[mh]'
-      unit_tests.resources = base_dir + 'Tests/Fixture/**/*'
-      unit_tests.requires_app_host = true
-      unit_tests.dependency 'OCMock'
-      unit_tests.dependency 'FirebaseInstanceID', '~> 4.2.0' # The version before FirebaseInstanceID updated to use FirebaseInstallations under the hood.
-    end
+  s.name             = 'FirebaseInstallations'
+  s.version          = '0.1.0'
+  s.summary          = 'Firebase Installations for iOS'
+
+  s.description      = <<-DESC
+  Firebase Installations for iOS.
+                       DESC
+
+  s.homepage         = 'https://firebase.google.com'
+  s.license          = { :type => 'Apache', :file => 'LICENSE' }
+  s.authors          = 'Google, Inc.'
+
+  s.source           = {
+    :git => 'https://github.com/firebase/firebase-ios-sdk.git',
+    :tag => 'Installations-' + s.version.to_s
+  }
+  s.social_media_url = 'https://twitter.com/Firebase'
+  s.ios.deployment_target = '8.0'
+  s.osx.deployment_target = '10.11'
+  s.tvos.deployment_target = '10.0'
+
+  s.cocoapods_version = '>= 1.4.0'
+  s.static_framework = true
+  s.prefix_header_file = false
+
+  base_dir = "FirebaseInstallations/Source/"
+  s.source_files = base_dir + 'Library/**/*.[mh]'
+  s.public_header_files = base_dir + 'Library/Public/*.h'
+
+  s.framework = 'Security'
+  s.dependency 'FirebaseCore', '~> 6.0'
+  s.dependency 'PromisesObjC', '~> 1.2'
+  s.dependency 'GoogleUtilities/UserDefaults', '~> 6.2'
+
+  preprocessor_definitions = 'FIRInstallations_LIB_VERSION=' + String(s.version)
+  if ENV['FIS_ALLOWS_INCOMPATIBLE_IID_VERSION'] && ENV['FIS_ALLOWS_INCOMPATIBLE_IID_VERSION'] == '1' then
+    # Disable FirebaseInstanceID compatibility assert to test IID migration.
+    preprocessor_definitions += ' FIR_INSTALLATIONS_ALLOWS_INCOMPATIBLE_IID_VERSION=1'
+  end
+  s.pod_target_xcconfig = {
+    'GCC_C_LANGUAGE_STANDARD' => 'c99',
+    'GCC_PREPROCESSOR_DEFINITIONS' => preprocessor_definitions
+  }
+
+  s.test_spec 'unit' do |unit_tests|
+    unit_tests.source_files = base_dir + 'Tests/Unit/**/*.[mh]',
+                              base_dir + 'Tests/Utils/**/*.[mh]'
+    unit_tests.resources = base_dir + 'Tests/Fixture/**/*'
+    unit_tests.requires_app_host = true
+    unit_tests.dependency 'OCMock'
+    unit_tests.dependency 'FirebaseInstanceID', '~> 4.2.0' # The version before FirebaseInstanceID updated to use FirebaseInstallations under the hood.
+
+  end
 
-    s.test_spec 'integration' do |int_tests|
-      int_tests.source_files = base_dir + 'Tests/Integration/**/*.[mh]'
-      int_tests.resources = base_dir + 'Tests/Resources/**/*'
-      s.pod_target_xcconfig = {
+  s.test_spec 'integration' do |int_tests|
+    int_tests.source_files = base_dir + 'Tests/Integration/**/*.[mh]'
+    int_tests.resources = base_dir + 'Tests/Resources/**/*'
+    if ENV['FIS_INTEGRATION_TESTS_REQUIRED'] && ENV['FIS_INTEGRATION_TESTS_REQUIRED'] == '1' then
+      int_tests.pod_target_xcconfig = {
       'GCC_PREPROCESSOR_DEFINITIONS' =>
         'FIR_INSTALLATIONS_INTEGRATION_TESTS_REQUIRED=1'
-    }
-      int_tests.requires_app_host = true
-      int_tests.dependency 'OCMock'
+      }
     end
+    int_tests.requires_app_host = true
+    int_tests.dependency 'OCMock'
   end
+end

+ 29 - 1
FirebaseInstallations/Source/Library/FIRInstallations.m

@@ -70,7 +70,7 @@ NS_ASSUME_NONNULL_BEGIN
 
   FIRComponent *installationsProvider =
       [FIRComponent componentWithProtocol:@protocol(FIRInstallationsInstanceProvider)
-                      instantiationTiming:FIRInstantiationTimingLazy
+                      instantiationTiming:FIRInstantiationTimingAlwaysEager
                              dependencies:@[]
                             creationBlock:creationBlock];
   return @[ installationsProvider ];
@@ -100,6 +100,8 @@ NS_ASSUME_NONNULL_BEGIN
                  prefetchAuthToken:(BOOL)prefetchAuthToken {
   self = [super init];
   if (self) {
+    [[self class] assertCompatibleIIDVersion];
+
     _appOptions = [appOptions copy];
     _appName = [appName copy];
     _installationsIDController = installationsIDController;
@@ -180,6 +182,32 @@ NS_ASSUME_NONNULL_BEGIN
       });
 }
 
+#pragma mark - IID version compatibility
+
++ (void)assertCompatibleIIDVersion {
+  // We use this flag to disable IID compatibility exception for unit tests.
+#ifdef FIR_INSTALLATIONS_ALLOWS_INCOMPATIBLE_IID_VERSION
+  return;
+#else
+  if (![self isIIDVersionCompatible]) {
+    [NSException raise:NSInternalInconsistencyException
+                format:@"FirebaseInstallations will not work correctly with current version of "
+                       @"Firebase Instance ID. Please update your Firebase Instance ID version."];
+  }
+#endif
+}
+
++ (BOOL)isIIDVersionCompatible {
+  Class IIDClass = NSClassFromString(@"FIRInstanceID");
+  if (IIDClass == nil) {
+    // It is OK if there is no IID at all.
+    return YES;
+  }
+  // We expect a compatible version having the method `+[FIRInstanceID usesFIS]` defined.
+  BOOL isCompatibleVersion = [IIDClass respondsToSelector:NSSelectorFromString(@"usesFIS")];
+  return isCompatibleVersion;
+}
+
 @end
 
 NS_ASSUME_NONNULL_END