FIRAnalyticsConfiguration.m 2.4 KB

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