No Description

FIRAnalyticsConfiguration.m 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #import <Foundation/Foundation.h>
  15. #import "Private/FIRAnalyticsConfiguration.h"
  16. #pragma clang diagnostic push
  17. #pragma clang diagnostic ignored "-Wdeprecated-implementations"
  18. @implementation FIRAnalyticsConfiguration
  19. #pragma clang diagnostic pop
  20. + (FIRAnalyticsConfiguration *)sharedInstance {
  21. static FIRAnalyticsConfiguration *sharedInstance = nil;
  22. static dispatch_once_t onceToken;
  23. dispatch_once(&onceToken, ^{
  24. sharedInstance = [[FIRAnalyticsConfiguration alloc] init];
  25. });
  26. return sharedInstance;
  27. }
  28. - (void)postNotificationName:(NSString *)name value:(id)value {
  29. if (!name.length || !value) {
  30. return;
  31. }
  32. [[NSNotificationCenter defaultCenter] postNotificationName:name
  33. object:self
  34. userInfo:@{name : value}];
  35. }
  36. - (void)setAnalyticsCollectionEnabled:(BOOL)analyticsCollectionEnabled {
  37. [self setAnalyticsCollectionEnabled:analyticsCollectionEnabled persistSetting:YES];
  38. }
  39. - (void)setAnalyticsCollectionEnabled:(BOOL)analyticsCollectionEnabled
  40. persistSetting:(BOOL)shouldPersist {
  41. // Persist the measurementEnabledState. Use FIRAnalyticsEnabledState values instead of YES/NO.
  42. FIRAnalyticsEnabledState analyticsEnabledState =
  43. analyticsCollectionEnabled ? kFIRAnalyticsEnabledStateSetYes : kFIRAnalyticsEnabledStateSetNo;
  44. if (shouldPersist) {
  45. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  46. [userDefaults setObject:@(analyticsEnabledState)
  47. forKey:kFIRAPersistedConfigMeasurementEnabledStateKey];
  48. [userDefaults synchronize];
  49. }
  50. [self postNotificationName:kFIRAnalyticsConfigurationSetEnabledNotification
  51. value:@(analyticsCollectionEnabled)];
  52. }
  53. @end