| 1 | 
           efrain | 
           1 | 
           /*
  | 
        
        
            | 
            | 
           2 | 
            * Copyright 2017 Google
  | 
        
        
            | 
            | 
           3 | 
            *
  | 
        
        
            | 
            | 
           4 | 
            * Licensed under the Apache License, Version 2.0 (the "License");
  | 
        
        
            | 
            | 
           5 | 
            * you may not use this file except in compliance with the License.
  | 
        
        
            | 
            | 
           6 | 
            * You may obtain a copy of the License at
  | 
        
        
            | 
            | 
           7 | 
            *
  | 
        
        
            | 
            | 
           8 | 
            *      http://www.apache.org/licenses/LICENSE-2.0
  | 
        
        
            | 
            | 
           9 | 
            *
  | 
        
        
            | 
            | 
           10 | 
            * Unless required by applicable law or agreed to in writing, software
  | 
        
        
            | 
            | 
           11 | 
            * distributed under the License is distributed on an "AS IS" BASIS,
  | 
        
        
            | 
            | 
           12 | 
            * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  | 
        
        
            | 
            | 
           13 | 
            * See the License for the specific language governing permissions and
  | 
        
        
            | 
            | 
           14 | 
            * limitations under the License.
  | 
        
        
            | 
            | 
           15 | 
            */
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
           #import <TargetConditionals.h>
  | 
        
        
            | 
            | 
           18 | 
           #if TARGET_OS_IOS || TARGET_OS_TV
  | 
        
        
            | 
            | 
           19 | 
              | 
        
        
            | 
            | 
           20 | 
           #import "FirebaseInAppMessaging/Sources/Public/FirebaseInAppMessaging/FIRInAppMessaging.h"
  | 
        
        
            | 
            | 
           21 | 
              | 
        
        
            | 
            | 
           22 | 
           #import <Foundation/Foundation.h>
  | 
        
        
            | 
            | 
           23 | 
              | 
        
        
            | 
            | 
           24 | 
           #import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
  | 
        
        
            | 
            | 
           25 | 
           #import "FirebaseInstallations/Source/Library/Private/FirebaseInstallationsInternal.h"
  | 
        
        
            | 
            | 
           26 | 
           #import "Interop/Analytics/Public/FIRAnalyticsInterop.h"
  | 
        
        
            | 
            | 
           27 | 
              | 
        
        
            | 
            | 
           28 | 
           #import "FirebaseInAppMessaging/Sources/FIRCore+InAppMessaging.h"
  | 
        
        
            | 
            | 
           29 | 
           #import "FirebaseInAppMessaging/Sources/FIRInAppMessagingPrivate.h"
  | 
        
        
            | 
            | 
           30 | 
           #import "FirebaseInAppMessaging/Sources/Private/Flows/FIRIAMDisplayExecutor.h"
  | 
        
        
            | 
            | 
           31 | 
           #import "FirebaseInAppMessaging/Sources/Private/Runtime/FIRIAMRuntimeManager.h"
  | 
        
        
            | 
            | 
           32 | 
           #import "FirebaseInAppMessaging/Sources/Private/Runtime/FIRInAppMessaging+Bootstrap.h"
  | 
        
        
            | 
            | 
           33 | 
              | 
        
        
            | 
            | 
           34 | 
           static BOOL _autoBootstrapOnFIRAppInit = YES;
  | 
        
        
            | 
            | 
           35 | 
              | 
        
        
            | 
            | 
           36 | 
           @implementation FIRInAppMessaging {
  | 
        
        
            | 
            | 
           37 | 
             BOOL _messageDisplaySuppressed;
  | 
        
        
            | 
            | 
           38 | 
           }
  | 
        
        
            | 
            | 
           39 | 
              | 
        
        
            | 
            | 
           40 | 
           // Call this to present the SDK being auto bootstrapped with other Firebase SDKs. It needs
  | 
        
        
            | 
            | 
           41 | 
           // to be triggered before [FIRApp configure] is executed. This should only be needed for
  | 
        
        
            | 
            | 
           42 | 
           // testing app that wants to use custom fiam SDK settings.
  | 
        
        
            | 
            | 
           43 | 
           + (void)disableAutoBootstrapWithFIRApp {
  | 
        
        
            | 
            | 
           44 | 
             _autoBootstrapOnFIRAppInit = NO;
  | 
        
        
            | 
            | 
           45 | 
           }
  | 
        
        
            | 
            | 
           46 | 
              | 
        
        
            | 
            | 
           47 | 
           + (void)load {
  | 
        
        
            | 
            | 
           48 | 
             [FIRApp registerInternalLibrary:(Class<FIRLibrary>)self withName:@"fire-fiam"];
  | 
        
        
            | 
            | 
           49 | 
           }
  | 
        
        
            | 
            | 
           50 | 
              | 
        
        
            | 
            | 
           51 | 
           + (nonnull NSArray<FIRComponent *> *)componentsToRegister {
  | 
        
        
            | 
            | 
           52 | 
             FIRDependency *analyticsDep = [FIRDependency dependencyWithProtocol:@protocol(FIRAnalyticsInterop)
  | 
        
        
            | 
            | 
           53 | 
                                                                      isRequired:YES];
  | 
        
        
            | 
            | 
           54 | 
             FIRComponentCreationBlock creationBlock =
  | 
        
        
            | 
            | 
           55 | 
                 ^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) {
  | 
        
        
            | 
            | 
           56 | 
               // Ensure it's cached so it returns the same instance every time fiam is called.
  | 
        
        
            | 
            | 
           57 | 
               *isCacheable = YES;
  | 
        
        
            | 
            | 
           58 | 
               id<FIRAnalyticsInterop> analytics = FIR_COMPONENT(FIRAnalyticsInterop, container);
  | 
        
        
            | 
            | 
           59 | 
               FIRInstallations *installations = [FIRInstallations installationsWithApp:container.app];
  | 
        
        
            | 
            | 
           60 | 
               return [[FIRInAppMessaging alloc] initWithAnalytics:analytics installations:installations];
  | 
        
        
            | 
            | 
           61 | 
             };
  | 
        
        
            | 
            | 
           62 | 
             FIRComponent *fiamProvider =
  | 
        
        
            | 
            | 
           63 | 
                 [FIRComponent componentWithProtocol:@protocol(FIRInAppMessagingInstanceProvider)
  | 
        
        
            | 
            | 
           64 | 
                                 instantiationTiming:FIRInstantiationTimingLazy
  | 
        
        
            | 
            | 
           65 | 
                                        dependencies:@[ analyticsDep ]
  | 
        
        
            | 
            | 
           66 | 
                                       creationBlock:creationBlock];
  | 
        
        
            | 
            | 
           67 | 
              | 
        
        
            | 
            | 
           68 | 
             return @[ fiamProvider ];
  | 
        
        
            | 
            | 
           69 | 
           }
  | 
        
        
            | 
            | 
           70 | 
              | 
        
        
            | 
            | 
           71 | 
           + (void)configureWithApp:(FIRApp *)app {
  | 
        
        
            | 
            | 
           72 | 
             if (!app.isDefaultApp) {
  | 
        
        
            | 
            | 
           73 | 
               // Only configure for the default FIRApp.
  | 
        
        
            | 
            | 
           74 | 
               FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM170000",
  | 
        
        
            | 
            | 
           75 | 
                           @"Firebase InAppMessaging only works with the default app.");
  | 
        
        
            | 
            | 
           76 | 
               return;
  | 
        
        
            | 
            | 
           77 | 
             }
  | 
        
        
            | 
            | 
           78 | 
              | 
        
        
            | 
            | 
           79 | 
             FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM170001",
  | 
        
        
            | 
            | 
           80 | 
                         @"Got notification for kFIRAppReadyToConfigureSDKNotification");
  | 
        
        
            | 
            | 
           81 | 
             if (_autoBootstrapOnFIRAppInit) {
  | 
        
        
            | 
            | 
           82 | 
               FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM170002",
  | 
        
        
            | 
            | 
           83 | 
                           @"Auto bootstrap Firebase in-app messaging SDK");
  | 
        
        
            | 
            | 
           84 | 
               [self bootstrapIAMFromFIRApp:app];
  | 
        
        
            | 
            | 
           85 | 
             } else {
  | 
        
        
            | 
            | 
           86 | 
               FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM170003",
  | 
        
        
            | 
            | 
           87 | 
                           @"No auto bootstrap Firebase in-app messaging SDK");
  | 
        
        
            | 
            | 
           88 | 
             }
  | 
        
        
            | 
            | 
           89 | 
           }
  | 
        
        
            | 
            | 
           90 | 
              | 
        
        
            | 
            | 
           91 | 
           - (instancetype)initWithAnalytics:(id<FIRAnalyticsInterop>)analytics
  | 
        
        
            | 
            | 
           92 | 
                               installations:(FIRInstallations *)installations {
  | 
        
        
            | 
            | 
           93 | 
             if (self = [super init]) {
  | 
        
        
            | 
            | 
           94 | 
               _messageDisplaySuppressed = NO;
  | 
        
        
            | 
            | 
           95 | 
               _analytics = analytics;
  | 
        
        
            | 
            | 
           96 | 
               _installations = installations;
  | 
        
        
            | 
            | 
           97 | 
             }
  | 
        
        
            | 
            | 
           98 | 
             return self;
  | 
        
        
            | 
            | 
           99 | 
           }
  | 
        
        
            | 
            | 
           100 | 
              | 
        
        
            | 
            | 
           101 | 
           + (FIRInAppMessaging *)inAppMessaging {
  | 
        
        
            | 
            | 
           102 | 
             FIRApp *defaultApp = [FIRApp defaultApp];  // Missing configure will be logged here.
  | 
        
        
            | 
            | 
           103 | 
             id<FIRInAppMessagingInstanceProvider> inAppMessaging =
  | 
        
        
            | 
            | 
           104 | 
                 FIR_COMPONENT(FIRInAppMessagingInstanceProvider, defaultApp.container);
  | 
        
        
            | 
            | 
           105 | 
             return (FIRInAppMessaging *)inAppMessaging;
  | 
        
        
            | 
            | 
           106 | 
           }
  | 
        
        
            | 
            | 
           107 | 
              | 
        
        
            | 
            | 
           108 | 
           - (BOOL)messageDisplaySuppressed {
  | 
        
        
            | 
            | 
           109 | 
             return _messageDisplaySuppressed;
  | 
        
        
            | 
            | 
           110 | 
           }
  | 
        
        
            | 
            | 
           111 | 
              | 
        
        
            | 
            | 
           112 | 
           - (void)setMessageDisplaySuppressed:(BOOL)suppressed {
  | 
        
        
            | 
            | 
           113 | 
             _messageDisplaySuppressed = suppressed;
  | 
        
        
            | 
            | 
           114 | 
             [[FIRIAMRuntimeManager getSDKRuntimeInstance] setShouldSuppressMessageDisplay:suppressed];
  | 
        
        
            | 
            | 
           115 | 
           }
  | 
        
        
            | 
            | 
           116 | 
              | 
        
        
            | 
            | 
           117 | 
           - (BOOL)automaticDataCollectionEnabled {
  | 
        
        
            | 
            | 
           118 | 
             return [FIRIAMRuntimeManager getSDKRuntimeInstance].automaticDataCollectionEnabled;
  | 
        
        
            | 
            | 
           119 | 
           }
  | 
        
        
            | 
            | 
           120 | 
              | 
        
        
            | 
            | 
           121 | 
           - (void)setAutomaticDataCollectionEnabled:(BOOL)automaticDataCollectionEnabled {
  | 
        
        
            | 
            | 
           122 | 
             [FIRIAMRuntimeManager getSDKRuntimeInstance].automaticDataCollectionEnabled =
  | 
        
        
            | 
            | 
           123 | 
                 automaticDataCollectionEnabled;
  | 
        
        
            | 
            | 
           124 | 
           }
  | 
        
        
            | 
            | 
           125 | 
              | 
        
        
            | 
            | 
           126 | 
           - (void)setMessageDisplayComponent:(id<FIRInAppMessagingDisplay>)messageDisplayComponent {
  | 
        
        
            | 
            | 
           127 | 
             _messageDisplayComponent = messageDisplayComponent;
  | 
        
        
            | 
            | 
           128 | 
              | 
        
        
            | 
            | 
           129 | 
             if (messageDisplayComponent == nil) {
  | 
        
        
            | 
            | 
           130 | 
               FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM290002", @"messageDisplayComponent set to nil.");
  | 
        
        
            | 
            | 
           131 | 
             } else {
  | 
        
        
            | 
            | 
           132 | 
               FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM290001",
  | 
        
        
            | 
            | 
           133 | 
                           @"Setting a non-nil message display component");
  | 
        
        
            | 
            | 
           134 | 
             }
  | 
        
        
            | 
            | 
           135 | 
              | 
        
        
            | 
            | 
           136 | 
             // Forward the setting to the display executor.
  | 
        
        
            | 
            | 
           137 | 
             [FIRIAMRuntimeManager getSDKRuntimeInstance].displayExecutor.messageDisplayComponent =
  | 
        
        
            | 
            | 
           138 | 
                 messageDisplayComponent;
  | 
        
        
            | 
            | 
           139 | 
           }
  | 
        
        
            | 
            | 
           140 | 
              | 
        
        
            | 
            | 
           141 | 
           - (void)triggerEvent:(NSString *)eventName {
  | 
        
        
            | 
            | 
           142 | 
             [[FIRIAMRuntimeManager getSDKRuntimeInstance].displayExecutor
  | 
        
        
            | 
            | 
           143 | 
                 checkAndDisplayNextContextualMessageForAnalyticsEvent:eventName];
  | 
        
        
            | 
            | 
           144 | 
           }
  | 
        
        
            | 
            | 
           145 | 
              | 
        
        
            | 
            | 
           146 | 
           @end
  | 
        
        
            | 
            | 
           147 | 
              | 
        
        
            | 
            | 
           148 | 
           #endif  // TARGET_OS_IOS || TARGET_OS_TV
  |