| 1 | 
           efrain | 
           1 | 
           // Copyright 2017 Google
  | 
        
        
            | 
            | 
           2 | 
           //
  | 
        
        
            | 
            | 
           3 | 
           // Licensed under the Apache License, Version 2.0 (the "License");
  | 
        
        
            | 
            | 
           4 | 
           // you may not use this file except in compliance with the License.
  | 
        
        
            | 
            | 
           5 | 
           // You may obtain a copy of the License at
  | 
        
        
            | 
            | 
           6 | 
           //
  | 
        
        
            | 
            | 
           7 | 
           //      http://www.apache.org/licenses/LICENSE-2.0
  | 
        
        
            | 
            | 
           8 | 
           //
  | 
        
        
            | 
            | 
           9 | 
           // Unless required by applicable law or agreed to in writing, software
  | 
        
        
            | 
            | 
           10 | 
           // distributed under the License is distributed on an "AS IS" BASIS,
  | 
        
        
            | 
            | 
           11 | 
           // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  | 
        
        
            | 
            | 
           12 | 
           // See the License for the specific language governing permissions and
  | 
        
        
            | 
            | 
           13 | 
           // limitations under the License.
  | 
        
        
            | 
            | 
           14 | 
              | 
        
        
            | 
            | 
           15 | 
           #import <Foundation/Foundation.h>
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
           #import "FirebaseCore/Sources/FIRAnalyticsConfiguration.h"
  | 
        
        
            | 
            | 
           18 | 
              | 
        
        
            | 
            | 
           19 | 
           #pragma clang diagnostic push
  | 
        
        
            | 
            | 
           20 | 
           #pragma clang diagnostic ignored "-Wdeprecated-implementations"
  | 
        
        
            | 
            | 
           21 | 
           @implementation FIRAnalyticsConfiguration
  | 
        
        
            | 
            | 
           22 | 
           #pragma clang diagnostic pop
  | 
        
        
            | 
            | 
           23 | 
              | 
        
        
            | 
            | 
           24 | 
           + (FIRAnalyticsConfiguration *)sharedInstance {
  | 
        
        
            | 
            | 
           25 | 
             static FIRAnalyticsConfiguration *sharedInstance = nil;
  | 
        
        
            | 
            | 
           26 | 
             static dispatch_once_t onceToken;
  | 
        
        
            | 
            | 
           27 | 
             dispatch_once(&onceToken, ^{
  | 
        
        
            | 
            | 
           28 | 
               sharedInstance = [[FIRAnalyticsConfiguration alloc] init];
  | 
        
        
            | 
            | 
           29 | 
             });
  | 
        
        
            | 
            | 
           30 | 
             return sharedInstance;
  | 
        
        
            | 
            | 
           31 | 
           }
  | 
        
        
            | 
            | 
           32 | 
              | 
        
        
            | 
            | 
           33 | 
           - (void)postNotificationName:(NSString *)name value:(id)value {
  | 
        
        
            | 
            | 
           34 | 
             if (!name.length || !value) {
  | 
        
        
            | 
            | 
           35 | 
               return;
  | 
        
        
            | 
            | 
           36 | 
             }
  | 
        
        
            | 
            | 
           37 | 
             [[NSNotificationCenter defaultCenter] postNotificationName:name
  | 
        
        
            | 
            | 
           38 | 
                                                                 object:self
  | 
        
        
            | 
            | 
           39 | 
                                                               userInfo:@{name : value}];
  | 
        
        
            | 
            | 
           40 | 
           }
  | 
        
        
            | 
            | 
           41 | 
              | 
        
        
            | 
            | 
           42 | 
           - (void)setAnalyticsCollectionEnabled:(BOOL)analyticsCollectionEnabled {
  | 
        
        
            | 
            | 
           43 | 
             [self setAnalyticsCollectionEnabled:analyticsCollectionEnabled persistSetting:YES];
  | 
        
        
            | 
            | 
           44 | 
           }
  | 
        
        
            | 
            | 
           45 | 
              | 
        
        
            | 
            | 
           46 | 
           - (void)setAnalyticsCollectionEnabled:(BOOL)analyticsCollectionEnabled
  | 
        
        
            | 
            | 
           47 | 
                                  persistSetting:(BOOL)shouldPersist {
  | 
        
        
            | 
            | 
           48 | 
             // Persist the measurementEnabledState. Use FIRAnalyticsEnabledState values instead of YES/NO.
  | 
        
        
            | 
            | 
           49 | 
             FIRAnalyticsEnabledState analyticsEnabledState =
  | 
        
        
            | 
            | 
           50 | 
                 analyticsCollectionEnabled ? kFIRAnalyticsEnabledStateSetYes : kFIRAnalyticsEnabledStateSetNo;
  | 
        
        
            | 
            | 
           51 | 
             if (shouldPersist) {
  | 
        
        
            | 
            | 
           52 | 
               NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  | 
        
        
            | 
            | 
           53 | 
               [userDefaults setObject:@(analyticsEnabledState)
  | 
        
        
            | 
            | 
           54 | 
                                forKey:kFIRAPersistedConfigMeasurementEnabledStateKey];
  | 
        
        
            | 
            | 
           55 | 
               [userDefaults synchronize];
  | 
        
        
            | 
            | 
           56 | 
             }
  | 
        
        
            | 
            | 
           57 | 
              | 
        
        
            | 
            | 
           58 | 
             [self postNotificationName:kFIRAnalyticsConfigurationSetEnabledNotification
  | 
        
        
            | 
            | 
           59 | 
                                  value:@(analyticsCollectionEnabled)];
  | 
        
        
            | 
            | 
           60 | 
           }
  | 
        
        
            | 
            | 
           61 | 
              | 
        
        
            | 
            | 
           62 | 
           @end
  |