Ingen beskrivning

FIRAnalyticsConfiguration.m 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #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)setMinimumSessionInterval:(NSTimeInterval)minimumSessionInterval {
  37. [self postNotificationName:kFIRAnalyticsConfigurationSetMinimumSessionIntervalNotification
  38. value:@(minimumSessionInterval)];
  39. }
  40. - (void)setSessionTimeoutInterval:(NSTimeInterval)sessionTimeoutInterval {
  41. [self postNotificationName:kFIRAnalyticsConfigurationSetSessionTimeoutIntervalNotification
  42. value:@(sessionTimeoutInterval)];
  43. }
  44. - (void)setAnalyticsCollectionEnabled:(BOOL)analyticsCollectionEnabled {
  45. [self setAnalyticsCollectionEnabled:analyticsCollectionEnabled persistSetting:YES];
  46. }
  47. - (void)setAnalyticsCollectionEnabled:(BOOL)analyticsCollectionEnabled
  48. persistSetting:(BOOL)shouldPersist {
  49. // Persist the measurementEnabledState. Use FIRAnalyticsEnabledState values instead of YES/NO.
  50. FIRAnalyticsEnabledState analyticsEnabledState =
  51. analyticsCollectionEnabled ? kFIRAnalyticsEnabledStateSetYes : kFIRAnalyticsEnabledStateSetNo;
  52. if (shouldPersist) {
  53. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  54. [userDefaults setObject:@(analyticsEnabledState)
  55. forKey:kFIRAPersistedConfigMeasurementEnabledStateKey];
  56. [userDefaults synchronize];
  57. }
  58. [self postNotificationName:kFIRAnalyticsConfigurationSetEnabledNotification
  59. value:@(analyticsCollectionEnabled)];
  60. }
  61. @end