Aby umożliwić użytkownikom włączanie i wyłączanie Firebase Performance Monitoring, możesz skonfigurować aplikację tak, aby można było włączać i wyłączać Performance Monitoring. Może się to przydać podczas tworzenia i testowania aplikacji.
Oto kilka opcji, które warto rozważyć:
Podczas tworzenia aplikacji możesz wyłączyć pakiet SDK Performance Monitoring i włączyć go ponownie w czasie działania.
Aplikację możesz utworzyć z włączonym pakietem SDK Performance Monitoring, ale w czasie działania możesz go wyłączyć za pomocą Firebase Remote Config.
Możesz całkowicie wyłączyć pakiet SDK Performance Monitoring bez możliwości włączenia go w czasie działania aplikacji.
Wyłącz Performance Monitoring podczas procesu tworzenia aplikacji.
Wyłączenie Performance Monitoring podczas procesu tworzenia aplikacji może być przydatne, aby uniknąć raportowania danych o skutecznoś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 na urządzenia Apple:
Aby wyłączyć Performance Monitoring, ale zezwolić aplikacji na włączenie jej w czasie działania, ustaw wartość
firebase_performance_collection_enabled
nafalse
w plikuInfo.plist
aplikacji.Aby całkowicie dezaktywować Performance Monitoring bez możliwości włączenia go w czasie działania, ustaw wartość
firebase_performance_collection_deactivated
natrue
w plikuInfo.plist
aplikacji.
Wyłączanie aplikacji w czasie działania za pomocą Remote Config
Firebase Remote Config umożliwia wprowadzanie zmian w zachowaniu i wyglądzie aplikacji, dzięki czemu jest idealnym sposobem na wyłączenie Performance Monitoring w wdrożonych instancjach aplikacji.
Aby wyłączyć zbieranie danych Performance Monitoring przy następnym uruchomieniu aplikacji na urządzenia Apple, użyj przykładowego kodu podanego poniżej. Więcej informacji o używaniu Remote Config w aplikacji na urządzenia Apple znajdziesz w artykule Używanie Firebase Remote Config na platformach Apple.
Sprawdź, czy w
Podfile
używasz Remote Config:pod 'Firebase/RemoteConfig'
Dodaj ten kod na początku pliku
AppDelegate
aplikacji:Swift
Uwaga: ten produkt Firebase nie jest dostępny na platformach macOS, Mac Catalyst i watchOS.import FirebaseRemoteConfig
Objective-C
Uwaga: ten produkt Firebase nie jest dostępny na platformach macOS, Mac Catalyst i watchOS.@import FirebaseRemoteConfig;
W pliku
AppDelegate
dodaj ten kod do instrukcjilaunchOptions
w metodzieapplication:didFinishLaunchingWithOptions:
instance:Swift
Uwaga: ten produkt nie jest dostępny w przypadku platform macOS, Mac Catalyst i 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: ten produkt Firebase nie jest dostępny na platformach 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.m
lub w innym pliku implementacji używanym przez aplikację dodaj ten kod, aby pobrać i aktywować wartości Remote Config:Swift
Uwaga: ten produkt Firebase nie jest dostępny na platformach 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: ten produkt Firebase nie jest dostępny na platformach 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 w projekcie aplikacji parametr perf_disable, a następnie ustaw jego wartość na
true
.Jeśli ustawisz wartość parametru perf_disable na
false
, Performance Monitoring pozostanie włączony.
Wyłączanie automatycznego lub niestandardowego zbierania danych
Możesz wprowadzić pewne zmiany w kodzie pokazanym powyżej i w Firebasekonsoli, aby wyłączyć całe automatyczne (gotowe) monitorowanie niezależnie od monitorowania niestandardowego.
Dodaj ten kod do instrukcji
launchOptions
w metodzie instancjiapplication:didFinishLaunchingWithOptions:
(zamiast tego, co pokazano powyżej w przypadku tej samej metody instancji):Swift
Uwaga: ten produkt Firebase nie jest dostępny na platformach 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: ten produkt Firebase nie jest dostępny na platformach 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 monitorowanie (gotowe do użycia), utwórz w projekcie aplikacji parametr perf_disable_auto, a następnie 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 monitorowanie (gotowe do użycia), utwórz w projekcie aplikacji parametr perf_disable_auto, a następnie ustaw jego wartość na