You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.7 KiB

6 years ago
  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. [self setAnalyticsCollectionEnabled:analyticsCollectionEnabled persistSetting:YES];
  43. }
  44. - (void)setAnalyticsCollectionEnabled:(BOOL)analyticsCollectionEnabled
  45. persistSetting:(BOOL)shouldPersist {
  46. // Persist the measurementEnabledState. Use FIRAnalyticsEnabledState values instead of YES/NO.
  47. FIRAnalyticsEnabledState analyticsEnabledState =
  48. analyticsCollectionEnabled ? kFIRAnalyticsEnabledStateSetYes : kFIRAnalyticsEnabledStateSetNo;
  49. if (shouldPersist) {
  50. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  51. [userDefaults setObject:@(analyticsEnabledState)
  52. forKey:kFIRAPersistedConfigMeasurementEnabledStateKey];
  53. [userDefaults synchronize];
  54. }
  55. [self postNotificationName:kFIRAnalyticsConfigurationSetEnabledNotification
  56. value:@(analyticsCollectionEnabled)];
  57. }
  58. @end