FIRAnalyticsConfiguration.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 "FirebaseCore/Sources/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. persistSetting:(BOOL)shouldPersist {
  38. // Persist the measurementEnabledState. Use FIRAnalyticsEnabledState values instead of YES/NO.
  39. FIRAnalyticsEnabledState analyticsEnabledState =
  40. analyticsCollectionEnabled ? kFIRAnalyticsEnabledStateSetYes : kFIRAnalyticsEnabledStateSetNo;
  41. if (shouldPersist) {
  42. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  43. [userDefaults setObject:@(analyticsEnabledState)
  44. forKey:kFIRAPersistedConfigMeasurementEnabledStateKey];
  45. [userDefaults synchronize];
  46. }
  47. [self postNotificationName:kFIRAnalyticsConfigurationSetEnabledNotification
  48. value:@(analyticsCollectionEnabled)];
  49. }
  50. @end