หากต้องการให้ผู้ใช้เลือกเข้าร่วมหรือเลือกไม่เข้าร่วมการใช้ Firebase Performance Monitoring คุณอาจ ต้องกำหนดค่าแอปเพื่อให้เปิดใช้และปิดใช้ Performance Monitoring ได้ นอกจากนี้ คุณอาจพบว่าความสามารถนี้มีประโยชน์ในระหว่างการพัฒนาและการทดสอบแอป
ตัวเลือกบางอย่างที่ควรพิจารณามีดังนี้
คุณสามารถปิดใช้ Performance Monitoring SDK เมื่อบิลด์แอป โดยมีตัวเลือกให้ เปิดใช้อีกครั้งในระหว่างรันไทม์
คุณสามารถบิลด์แอปโดยเปิดใช้ Performance Monitoring SDK แต่มีตัวเลือกให้ ปิดใช้ในระหว่างรันไทม์โดยใช้ 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, watchOSimport FirebaseRemoteConfigObjective-C
หมายเหตุ: ผลิตภัณฑ์ Firebase นี้ไม่พร้อมใช้งานในเป้าหมาย macOS, Mac Catalyst, watchOS@import FirebaseRemoteConfig;ในไฟล์
AppDelegateให้เพิ่มโค้ดต่อไปนี้ลงในคำสั่งlaunchOptionsในเมธอดอินสแตนซ์application:didFinishLaunchingWithOptions:Swift
หมายเหตุ: ผลิตภัณฑ์นี้ไม่พร้อมใช้งานในเป้าหมาย macOS, Mac Catalyst, watchOSremoteConfig = 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, watchOSself.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 เป็น
falsePerformance Monitoring จะยังคง เปิดใช้
ปิดใช้การเก็บรวบรวมข้อมูลอัตโนมัติหรือการเก็บรวบรวมข้อมูลที่กำหนดเองแยกกัน
คุณสามารถทำการเปลี่ยนแปลงโค้ดที่แสดงด้านบนและในคอนโซล Firebase เพื่อให้คุณปิดใช้การตรวจสอบอัตโนมัติทั้งหมด (พร้อมใช้งานทันที) แยกจากการตรวจสอบที่กำหนดเองได้
เพิ่มโค้ดต่อไปนี้ลงในคำสั่ง
launchOptionsในเมธอดอินสแตนซ์application:didFinishLaunchingWithOptions:(แทนโค้ดที่แสดงด้านบนสำหรับเมธอดอินสแตนซ์เดียวกัน)Swift
หมายเหตุ: ผลิตภัณฑ์ Firebase นี้ไม่พร้อมใช้งานในเป้าหมาย macOS, Mac Catalyst, watchOSremoteConfig = 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, watchOSself.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 พารามิเตอร์ในโปรเจ็กต์ของแอป แล้วตั้งค่า
เป็น