للسماح للمستخدمين بتفعيل ميزة 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 FirebaseRemoteConfig
Objective-C
ملاحظة: لا يتوفّر منتج Firebase هذا على أنظمة التشغيل macOS وMac Catalyst وwatchOS.@import FirebaseRemoteConfig;
في ملف
AppDelegate
، أضِف الرمز التالي إلى عباراتlaunchOptions
في طريقةapplication:didFinishLaunchingWithOptions:
instance: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:
instance (بدلاً من الرمز المعروض أعلاه لطريقة instance نفسها):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 في مشروع تطبيقك، ثم اضبط قيمتها على