Aby umożliwić użytkownikom akceptację lub rezygnację z używania Firebase Performance Monitoring, możesz skonfigurować aplikację tak, aby można było włączać i wyłączać funkcję Performance Monitoring. Ta funkcja może być też przydatna podczas tworzenia i testowania aplikacji.
Oto kilka opcji, które warto rozważyć:
Możesz wyłączyć pakiet SDK Performance Monitoring podczas tworzenia aplikacji, a potem ponownie go włączyć w czasie działania.
Możesz utworzyć aplikację z włączonym pakietem SDK Performance Monitoring, ale możesz go wyłączyć w czasie działania za pomocą Firebase Remote Config.
Możesz całkowicie dezaktywować pakiet SDK Performance Monitoring bez możliwości włączenia go w czasie działania.
Wyłączanie Performance Monitoring podczas procesu kompilacji aplikacji
Wyłączenie Performance Monitoring podczas procesu kompilacji aplikacji może być przydatne, gdy chcesz uniknąć raportowania danych o wydajności z wersji przedpremierowej aplikacji podczas jej tworzenia i testowania.
Aby wyłączyć lub dezaktywować Performance Monitoring, możesz dodać jeden z 2 kluczy do pliku listy właściwości (Info.plist) aplikacji Apple:
Aby wyłączyć Performance Monitoring, ale zezwolić aplikacji na włączenie tej funkcji w czasie działania, ustaw
firebase_performance_collection_enablednafalsew plikuInfo.plistaplikacji.Aby całkowicie wyłączyć Performance Monitoring bez możliwości włączenia w czasie działania, ustaw
firebase_performance_collection_deactivatednatruew plikuInfo.plistaplikacji.
Wyłączanie aplikacji w czasie działania za pomocą Remote Config
Firebase Remote Config pozwala zmieniać działanie i wygląd aplikacji, dzięki czemu jest to idealny sposób na wyłączenie Performance Monitoring we wdrożonych instancjach aplikacji.
Aby wyłączyć zbieranie danych przez Performance Monitoring przy następnym uruchomieniu aplikacji na urządzeniu Apple, użyj przykładowego kodu podanego poniżej. Więcej informacji o używaniu Remote Config w aplikacji Apple znajdziesz w artykule Korzystanie z Firebase Remote Config na platformach Apple.
Upewnij się, że w
Podfileużywasz Remote Config:pod 'Firebase/RemoteConfig'Dodaj te informacje na początku pliku
AppDelegateaplikacji:Swift
Uwaga: ta usługa Firebase nie jest dostępna na urządzeniach z systemem macOS, Mac Catalyst i watchOS.import FirebaseRemoteConfigObjective-C
Uwaga: ta usługa Firebase nie jest dostępna na urządzeniach z systemem macOS, Mac Catalyst i watchOS.@import FirebaseRemoteConfig;W pliku
AppDelegatedodaj ten kod do instrukcjilaunchOptionsw metodzie instancjiapplication:didFinishLaunchingWithOptions::Swift
Uwaga: ta usługa nie jest dostępna na urządzeniach z systemem macOS, Mac Catalyst ani watchOS.remoteConfig = RemoteConfig.remoteConfig() // You can change the "false" below to "true" to permit more fetches when validating // your app, but you should change it back to "false" or remove this statement before // distributing your app in production. let remoteConfigSettings = RemoteConfigSettings(developerModeEnabled: false) remoteConfig.configSettings = remoteConfigSettings! // Load in-app defaults from a plist file that sets perf_disable to false until // you update values in the Firebase console. remoteConfig.setDefaultsFromPlistFileName("RemoteConfigDefaults") // Important! This needs to be applied before FirebaseApp.configure() if !remoteConfig["perf_disable"].boolValue { // The following line disables all automatic (out-of-the-box) monitoring Performance.sharedInstance().isInstrumentationEnabled = false // The following line disables all custom monitoring Performance.sharedInstance().isDataCollectionEnabled = false } else { Performance.sharedInstance().isInstrumentationEnabled = true Performance.sharedInstance().isDataCollectionEnabled = true } // Use Firebase library to configure APIs FirebaseApp.configure()Objective-C
Uwaga: ta usługa Firebase nie jest dostępna na urządzeniach z systemem macOS, Mac Catalyst i watchOS.self.remoteConfig = [FIRRemoteConfig remoteConfig]; // You can change the NO below to YES to permit more fetches when validating // your app, but you should change it back to NO or remove this statement before // distributing your app in production. FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:NO]; self.remoteConfig.configSettings = remoteConfigSettings; // Load in-app defaults from a plist file that sets perf_disable to false until // you update values in the Firebase console. [self.remoteConfig setDefaultsFromPlistFileName:@"RemoteConfigDefaults"]; // Important! This needs to be applied before [FIRApp configure] if (!self.remoteConfig[@"perf_disable"].numberValue.boolValue) { // The following line disables all automatic (out-of-the-box) monitoring [FIRPerformance sharedInstance].instrumentationEnabled = NO; // The following line disables all custom monitoring [FIRPerformance sharedInstance].dataCollectionEnabled = NO; } else { [FIRPerformance sharedInstance].instrumentationEnabled = YES; [FIRPerformance sharedInstance].dataCollectionEnabled = YES; } // Use Firebase library to configure APIs [FIRApp configure];W pliku
ViewController.mlub innym pliku implementacji używanym przez aplikację dodaj ten kod, aby pobierać i aktywować wartości Remote Config:Swift
Uwaga: ta usługa Firebase nie jest dostępna na urządzeniach z systemem macOS, Mac Catalyst i watchOS.//RemoteConfig fetch and activation in your app, shortly after startup remoteConfig.fetch(withExpirationDuration: TimeInterval(30.0)) { (status, error) -> Void in if status == .success { print("Config fetched!") self.remoteConfig.activateFetched() } else { print("Config not fetched") print("Error \(error!.localizedDescription)") } }Objective-C
Uwaga: ta usługa Firebase nie jest dostępna na urządzeniach z systemem macOS, Mac Catalyst i watchOS.//RemoteConfig fetch and activation in your app, shortly after startup [self.remoteConfig fetchWithExpirationDuration:30.0 completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *error) { if (status == FIRRemoteConfigFetchStatusSuccess) { NSLog(@"Config fetched!"); [self.remoteConfig activateFetched]; } else { NSLog(@"Config not fetched"); NSLog(@"Error %@", error.localizedDescription); } }];Aby wyłączyć Performance Monitoring w konsoli Firebase, utwórz parametr perf_disable w projekcie aplikacji, a następnie ustaw jego wartość na
true.Jeśli ustawisz wartość perf_disable na
false, Performance Monitoring pozostanie włączony.
Wyłączanie zbierania danych automatycznych lub niestandardowych
Możesz wprowadzić pewne zmiany w kodzie pokazanym powyżej i w konsoli Firebase, aby wyłączyć całe automatyczne (gotowe) monitorowanie niezależnie od monitorowania niestandardowego.
Dodaj ten kod do instrukcji
launchOptionsw metodzie instancjiapplication:didFinishLaunchingWithOptions:(zamiast tego, co pokazano powyżej w przypadku tej samej metody instancji):Swift
Uwaga: ta usługa Firebase nie jest dostępna na urządzeniach z systemem macOS, Mac Catalyst i watchOS.remoteConfig = FIRRemoteConfig.remoteConfig() let remoteConfigSettings = FIRRemoteConfigSettings(developerModeEnabled: true) remoteConfig.configSettings = remoteConfigSettings! // Important! This needs to be applied before FirebaseApp.configure() if remoteConfig["perf_disable_auto"].boolValue { // The following line disables all automatic (out-of-the-box) monitoring Performance.sharedInstance().isInstrumentationEnabled = false } else { Performance.sharedInstance().isInstrumentationEnabled = true } if remoteConfig["perf_disable_manual"].boolValue { // The following line disables all custom monitoring Performance.sharedInstance().isDataCollectionEnabled = false } else { Performance.sharedInstance().isDataCollectionEnabled = true } // Use Firebase library to configure APIs FirebaseApp.configure()Objective-C
Uwaga: ta usługa Firebase nie jest dostępna na urządzeniach z systemem macOS, Mac Catalyst i watchOS.self.remoteConfig = [FIRRemoteConfig remoteConfig]; FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:YES]; self.remoteConfig.configSettings = remoteConfigSettings; // Important! This needs to be applied before [FirebaseApp configure] if (self.remoteConfig[@"perf_disable_auto"].numberValue.boolValue) { // The following line disables all automatic (out-of-the-box) monitoring [FIRPerformance sharedInstance].instrumentationEnabled = NO; } else { [FIRPerformance sharedInstance].instrumentationEnabled = YES; } if (self.remoteConfig[@"perf_disable_manual"].numberValue.boolValue) { // The following line disables all custom monitoring [FIRPerformance sharedInstance].dataCollectionEnabled = NO; } else { [FIRPerformance sharedInstance].dataCollectionEnabled = YES; } // Use Firebase library to configure APIs [FirebaseApp configure];W konsoli Firebase wykonaj te czynności:
- Aby wyłączyć całe automatyczne (gotowe) monitorowanie, utwórz w projekcie aplikacji parametr perf_disable_auto i ustaw jego wartość na
true. - Aby wyłączyć całe monitorowanie niestandardowe, utwórz w projekcie aplikacji parametr perf_disable_manual i ustaw jego wartość na
true.
- Aby wyłączyć całe automatyczne (gotowe) monitorowanie, utwórz w projekcie aplikacji parametr perf_disable_auto i ustaw jego wartość na