כדי לאפשר למשתמשים להביע הסכמה או לבטל את ההסכמה לשימוש ב-Firebase Performance Monitoring, כדאי להגדיר את האפליקציה כך שתוכלו להפעיל ולהשבית את Performance Monitoring. יכול להיות שהיכולת הזו תהיה שימושית גם במהלך הפיתוח והבדיקה של אפליקציות.
הנה כמה אפשרויות שכדאי להביא בחשבון:
אפשר להשבית את Performance Monitoring SDK כשמפתחים את האפליקציה, ויש אפשרות להפעיל אותו מחדש בזמן הריצה.
אפשר ליצור את האפליקציה עם ה-SDK Performance Monitoring מופעל, אבל יש אפשרות להשבית אותו בזמן הריצה באמצעות Firebase Remote Config.
אפשר להשבית לגמרי את Performance Monitoring SDK, בלי אפשרות להפעיל אותו בזמן ריצה.
השבתה של 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 FirebaseRemoteConfig
Objective-C
הערה: מוצר Firebase הזה לא זמין ב-macOS, ב-Mac Catalyst ובמטרות watchOS.@import FirebaseRemoteConfig;
בקובץ
AppDelegate
, מוסיפים את הקוד הבא להצהרותlaunchOptions
בשיטת המופע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
בשיטת המופעapplication:didFinishLaunchingWithOptions:
(במקום מה שמוצג למעלה עבור אותה שיטת מופע):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 בפרויקט של האפליקציה ומגדירים את הערך שלו ל-