כדי לאפשר למשתמשים להביע הסכמה או לבטל את ההסכמה לשימוש ב-Firebase Performance Monitoring, כדאי להגדיר את האפליקציה כך שתוכלו להפעיל ולהשבית את Performance Monitoring. היכולת הזו יכולה להיות שימושית גם במהלך הפיתוח והבדיקה של האפליקציה.
הנה כמה אפשרויות שכדאי לבדוק:
אתם יכולים להשבית את ה-SDK של Performance Monitoring כשאתם מפתחים את האפליקציה, ולהפעיל אותו מחדש בזמן הריצה.
אתם יכולים לפתח את האפליקציה כשה-SDK של Performance Monitoring מופעל, אבל יש לכם אפשרות להשבית אותו בזמן הריצה באמצעות Firebase Remote Config.
אפשר להשבית לגמרי את ה-SDK של Performance Monitoring, בלי אפשרות להפעיל אותו בזמן ריצה.
השבתת Performance Monitoring במהלך תהליך פיתוח האפליקציה
מצב אחד שבו השבתת Performance Monitoring במהלך תהליך פיתוח האפליקציה יכולה להיות שימושית הוא כדי להימנע מדיווח על נתוני ביצועים מגרסת טרום-השקה של האפליקציה במהלך הפיתוח והבדיקה שלה.
כדי להשבית או לבטל את ההפעלה של Performance Monitoring, אתם יכולים להוסיף אחד משני מפתחות לקובץ רשימת המאפיינים (Info.plist) של האפליקציה ל-Apple:
כדי להשבית את Performance Monitoring, אבל לאפשר לאפליקציה להפעיל אותו בזמן הריצה, צריך להגדיר את
firebase_performance_collection_enabledל-falseבקובץInfo.plistשל האפליקציה.כדי להשבית לחלוטין את Performance Monitoring, בלי אפשרות להפעיל אותו בזמן הריצה, מגדירים את
firebase_performance_collection_deactivatedכ-trueבקובץInfo.plistשל האפליקציה.
השבתת האפליקציה בזמן הריצה באמצעות Remote Config
Firebase Remote Config מאפשרת לכם לבצע שינויים בהתנהגות ובמראה של האפליקציה, כך שזו דרך אידיאלית להשבית את Performance Monitoring במופעים של האפליקציה שנפרסו.
כדי להשבית את איסוף הנתונים של Performance Monitoring בפעם הבאה שהאפליקציה ל-Apple תופעל, צריך להשתמש בקוד לדוגמה שמוצג בהמשך. מידע נוסף על השימוש ב-Remote Config באפליקציה של Apple זמין במאמר שימוש ב-Firebase Remote Config בפלטפורמות של Apple.
צריך לוודא ש-Remote Config מוגדר ב-
Podfile:pod 'Firebase/RemoteConfig'מוסיפים את הקוד הבא לחלק העליון של קובץ
AppDelegateשל האפליקציה:Swift
הערה: מוצר Firebase הזה לא זמין ביעדים של macOS, Mac Catalyst ו-watchOS.import FirebaseRemoteConfigObjective-C
הערה: מוצר Firebase הזה לא זמין ביעדים של macOS, Mac Catalyst ו-watchOS.@import FirebaseRemoteConfig;בקובץ
AppDelegate, מוסיפים את הקוד הבא להצהרותlaunchOptionsב-method של המכונהapplication:didFinishLaunchingWithOptions::Swift
הערה: המוצר הזה לא זמין ביעדים של macOS, Mac Catalyst ו-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
הערה: מוצר Firebase הזה לא זמין ביעדים של macOS, Mac Catalyst ו-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];בקובץ
ViewController.mאו בקובץ הטמעה אחר שמשמש את האפליקציה, מוסיפים את הקוד הבא כדי לאחזר ולהפעיל את הערכים של Remote Config:Swift
הערה: מוצר Firebase הזה לא זמין ביעדים של macOS, Mac Catalyst ו-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
הערה: מוצר Firebase הזה לא זמין ביעדים של macOS, Mac Catalyst ו-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); } }];כדי להשבית את Performance Monitoring במסוף Firebase, צריך ליצור פרמטר perf_disable בפרויקט של האפליקציה ולהגדיר את הערך שלו ל-
true.אם מגדירים את הערך של perf_disable ל-
false, Performance Monitoring נשאר מופעל.
השבתה של איסוף נתונים אוטומטי או מותאם אישית בנפרד
אתם יכולים לבצע כמה שינויים בקוד שמוצג למעלה ובמסוף Firebase כדי להשבית את כל המעקב האוטומטי (המוכן לשימוש) בנפרד מהמעקב בהתאמה אישית.
מוסיפים את הקוד הבא להצהרות
launchOptionsב-method של המכונהapplication:didFinishLaunchingWithOptions:(במקום מה שמוצג למעלה לאותו method של המכונה):Swift
הערה: מוצר Firebase הזה לא זמין ביעדים של macOS, Mac Catalyst ו-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
הערה: מוצר Firebase הזה לא זמין ביעדים של macOS, Mac Catalyst ו-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];מבצעים את הפעולות הבאות במסוף Firebase:
- כדי להשבית את כל המעקב האוטומטי (המוכן לשימוש), יוצרים פרמטר perf_disable_auto בפרויקט של האפליקציה ומגדירים את הערך שלו ל-
true. - כדי להשבית את כל המעקב בהתאמה אישית, יוצרים פרמטר perf_disable_manual בפרויקט של האפליקציה ומגדירים את הערך שלו ל-
true.
- כדי להשבית את כל המעקב האוטומטי (המוכן לשימוש), יוצרים פרמטר perf_disable_auto בפרויקט של האפליקציה ומגדירים את הערך שלו ל-