简体   繁体   中英

Why i need to set Analytics.setAnalyticsCollectionEnabled(true) if it is true as default ? Firebase + iOS

Since my last update firebase dashboard is almost empty. At first I did think is new iOS 14.5 policy problem but refer to:

https://firebase.google.com/docs/ios/supporting-ios-14

I play around with settings and noticed that when I use

Analytics.setAnalyticsCollectionEnabled(true)

Firebase starts to provide data in real time as i have -FIRDebugEnabled. But without calling it, I don't get firebase logs even in console looks like they are not send at all. Why I need to Analytics.setAnalyticsCollectionEnabled(true) if there is information This setting is persisted across app sessions. By default it is enabled? Or I am just missing something?

In that time I did update pods to newest version for:

pod 'Firebase/Crashlytics'
pod 'Firebase/AnalyticsWithoutAdIdSupport'
pod 'Firebase/Messaging'

Did you perhaps disable collection in your plist file? Doing so would require you to override the setting at runtime in order to enable analytics collection. https://firebase.google.com/docs/analytics/configure-data-collection#objective-c

Looks like this might be caused by the linker. Especially since FIRAnalytics is not used anywhere in your project and simply is not linked into the main binary. Then Firebase framework detects that there are no FIRAnalytics class and is not initiating analytics: ( FIRApp.m )

- (BOOL)configureCore {
  [self checkExpectedBundleID];
  if (![self isAppIDValid]) {
    return NO;
  }

  // Initialize the Analytics once there is a valid options under default app. Analytics should
  // always initialize first by itself before the other SDKs.
  if ([self.name isEqualToString:kFIRDefaultAppName]) {
    Class firAnalyticsClass = NSClassFromString(@"FIRAnalytics");
    if (firAnalyticsClass) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
      SEL startWithConfigurationSelector = @selector(startWithConfiguration:options:);
#pragma clang diagnostic pop
      if ([firAnalyticsClass respondsToSelector:startWithConfigurationSelector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        [firAnalyticsClass performSelector:startWithConfigurationSelector
                                withObject:[FIRConfiguration sharedInstance].analyticsConfiguration
                                withObject:_options];
#pragma clang diagnostic pop
      }
    }
  }

As I see there are two possible solutions:

  1. Use FIRAnalytics (for Objective-C) or Analytics (for Swift) from FirebaseAnalytics somewhere in your main binary to force the linker to link it.
  2. Use some linker flag to force link FirebaseAnalytics lib. This could be -ObjC , -force_load or even -all_load .

I'd personally go with the first option because after some time you will use that class to log your custom events anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM