หากต้องการให้ผู้ใช้เลือกใช้หรือไม่ใช้การตรวจสอบประสิทธิภาพ Firebase คุณอาจต้องกำหนดค่าแอปเพื่อให้สามารถเปิดและปิดใช้งานการตรวจสอบประสิทธิภาพได้ คุณอาจพบว่าความสามารถนี้มีประโยชน์ในระหว่างการพัฒนาและทดสอบแอป
ต่อไปนี้เป็นตัวเลือกที่ควรพิจารณา:
คุณสามารถปิดใช้งาน Performance Monitoring SDK เมื่อสร้างแอปของคุณ โดยมีตัวเลือกในการเปิดใช้งานอีกครั้งเมื่อรันไทม์
คุณสร้างแอปได้โดยเปิดใช้ Performance Monitoring SDK แต่มีตัวเลือกให้ปิดใช้ในขณะรันไทม์โดยใช้ Firebase Remote Config
คุณสามารถปิดใช้งาน Performance Monitoring SDK ได้อย่างสมบูรณ์ โดยไม่มีตัวเลือกในการเปิดใช้งานในขณะรันไทม์
ปิดใช้งานการตรวจสอบประสิทธิภาพระหว่างกระบวนการสร้างแอปของคุณ
สถานการณ์หนึ่งที่การปิดใช้งานการตรวจสอบประสิทธิภาพระหว่างกระบวนการสร้างแอปอาจมีประโยชน์คือการหลีกเลี่ยงการรายงานข้อมูลประสิทธิภาพจากแอปเวอร์ชันก่อนเผยแพร่ในระหว่างการพัฒนาและทดสอบแอป
หากต้องการปิดหรือปิดใช้งาน Performance Monitoring คุณสามารถเพิ่มหนึ่งในสองคีย์ไปยังไฟล์รายการคุณสมบัติ ( Info.plist
) สำหรับแอพ Apple ของคุณ:
หากต้องการปิดใช้การตรวจสอบประสิทธิภาพ แต่อนุญาตให้แอปเปิดใช้งานในขณะรันไทม์ ให้ตั้งค่า
firebase_performance_collection_enabled
เป็นfalse
ในไฟล์Info.plist
ของแอปหากต้องการปิดใช้งานการตรวจสอบประสิทธิภาพโดยสมบูรณ์ โดยไม่มีตัวเลือกให้เปิดใช้งานขณะรันไทม์ ให้ตั้งค่า
firebase_performance_collection_deactivated
เป็นtrue
ในไฟล์Info.plist
ของแอป
ปิดใช้งานแอปของคุณขณะรันไทม์โดยใช้ Remote Config
การกำหนดค่าระยะไกลของ Firebase ช่วยให้คุณเปลี่ยนแปลงลักษณะการทำงานและรูปลักษณ์ของแอปได้ ดังนั้นจึงเป็นวิธีที่เหมาะที่จะให้คุณปิดใช้การตรวจสอบประสิทธิภาพในอินสแตนซ์ที่ทำให้แอปใช้งานได้
หากต้องการปิดใช้งานการรวบรวมข้อมูลการตรวจสอบประสิทธิภาพในครั้งต่อไปที่แอป Apple ของคุณเริ่มทำงาน ให้ใช้โค้ดตัวอย่างที่แสดงด้านล่าง สำหรับข้อมูลเพิ่มเติมเกี่ยวกับการใช้การกำหนดค่าระยะไกลในแอป Apple ให้ดู ที่ ใช้การกำหนดค่าระยะไกลของ Firebase บนแพลตฟอร์มของ Apple
ตรวจสอบให้แน่ใจว่าใช้ Remote Config ใน
Podfile
ของคุณ :pod 'Firebase/RemoteConfig'
เพิ่มสิ่งต่อไปนี้ที่ด้านบนของไฟล์
AppDelegate
ของแอปของคุณ:สวิฟต์
หมายเหตุ: ผลิตภัณฑ์ Firebase นี้ไม่พร้อมใช้งานบน macOS, Mac Catalyst, watchOS เป้าหมายimport FirebaseRemoteConfig
วัตถุประสงค์-C
หมายเหตุ: ผลิตภัณฑ์ Firebase นี้ไม่พร้อมใช้งานบน macOS, Mac Catalyst, watchOS เป้าหมาย@import FirebaseRemoteConfig;
ในไฟล์
AppDelegate
ของคุณ ให้เพิ่มโค้ดต่อไปนี้ในคำสั่งlaunchOptions
ในapplication:didFinishLaunchingWithOptions:
วิธีการอินสแตนซ์:สวิฟต์
หมายเหตุ: ผลิตภัณฑ์นี้ไม่พร้อมใช้งานบน 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()
วัตถุประสงค์-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
หรือไฟล์การใช้งานอื่นๆ ที่แอปของคุณใช้ ให้เพิ่มโค้ดต่อไปนี้เพื่อดึงข้อมูลและเปิดใช้งานค่าคอนฟิกระยะไกล:สวิฟต์
หมายเหตุ: ผลิตภัณฑ์ 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)") } }
วัตถุประสงค์-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); } }];
หากต้องการปิดใช้การตรวจสอบประสิทธิภาพในคอนโซล Firebase ให้สร้างพารามิเตอร์ perf_disable ในโครงการของแอป จากนั้นตั้งค่าเป็น
true
หากคุณตั้งค่า perf_disable เป็น
false
การมอนิเตอร์ประสิทธิภาพจะยังคงเปิดใช้งานอยู่
ปิดใช้งานการรวบรวมข้อมูลอัตโนมัติหรือกำหนดเองแยกกัน
คุณสามารถทำการเปลี่ยนแปลงบางอย่างกับโค้ดที่แสดงด้านบนและในคอนโซล Firebase เพื่อให้คุณสามารถปิดใช้งานการตรวจสอบอัตโนมัติทั้งหมด (ทันทีที่แกะกล่อง) แยกจากการตรวจสอบแบบกำหนดเอง
เพิ่มโค้ดต่อไปนี้ในคำสั่ง
launchOptions
ในapplication:didFinishLaunchingWithOptions:
วิธีการอินสแตนซ์ (แทนที่แสดงไว้ด้านบนสำหรับวิธีการอินสแตนซ์เดียวกัน):สวิฟต์
หมายเหตุ: ผลิตภัณฑ์ 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()
วัตถุประสงค์-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 ในโครงการของแอป จากนั้นตั้งค่าเป็น