إيقاف مراقبة أداء Firebase

للسماح للمستخدمين بالموافقة على استخدام مراقبة أداء Firebase أو إيقافها، قد تحتاج إلى إعداد تطبيقك بحيث يمكنك تفعيل ميزة "مراقبة الأداء" أو إيقافها. وقد تجد أيضًا هذه الإمكانية مفيدة أثناء تطوير التطبيقات واختبارها.

في ما يلي بعض الخيارات التي يجب أخذها في الاعتبار:

  • يمكنك إيقاف حزمة تطوير البرامج (SDK) لمراقبة الأداء أثناء إنشاء تطبيقك، ويمكنك إعادة تفعيلها في وقت التشغيل.

  • يمكنك إنشاء تطبيقك في حال تفعيل حزمة تطوير البرامج (SDK) لمراقبة الأداء، ولكن يمكنك إيقافه في وقت التشغيل باستخدام ميزة "الإعداد عن بُعد في Firebase".

  • يمكنك إيقاف حزمة تطوير البرامج (SDK) الخاصة بمراقبة الأداء تمامًا بدون أي خيار لتفعيلها في وقت التشغيل.

إيقاف ميزة "مراقبة الأداء" أثناء عملية إنشاء تطبيقك

من المفيد تجنّب الإبلاغ عن بيانات الأداء من إصدار تجريبي لتطبيقك أثناء تطوير التطبيق واختباره من خلال إيقاف ميزة "مراقبة الأداء" أثناء عملية تصميم التطبيق.

لإيقاف ميزة "مراقبة الأداء" أو إيقافها، يمكنك إضافة أحد المفتاحَين إلى ملف قائمة الخصائص (Info.plist) لتطبيق Apple:

  • لإيقاف ميزة "مراقبة الأداء" مع السماح لتطبيقك بتفعيلها في وقت التشغيل، اضبط firebase_performance_collection_enabled على false في ملف Info.plist الخاص بتطبيقك.

  • لإيقاف ميزة "مراقبة الأداء" تمامًا بدون خيار تفعيلها في وقت التشغيل، اضبط firebase_performance_collection_deactivated على true في ملف Info.plist الخاص بتطبيقك.

إيقاف تطبيقك في وقت التشغيل باستخدام ميزة "الإعداد عن بُعد"

تتيح لك ميزة "الإعداد عن بُعد في Firebase" إجراء تغييرات على سلوك تطبيقك ومظهره، وبالتالي توفير طريقة مثالية للسماح لك بإيقاف "مراقبة الأداء" في مثيلات التطبيق التي تم نشرها.

لإيقاف جمع بيانات "مراقبة الأداء" في المرة القادمة التي يبدأ فيها تطبيق Apple، استخدِم الرمز النموذجي الموضّح أدناه. لمزيد من المعلومات عن استخدام "الإعداد عن بُعد" في تطبيق Apple، يُرجى الاطّلاع على استخدام "الإعداد عن بُعد في Firebase" في أنظمة Apple الأساسية.

  1. تأكَّد من استخدام ميزة "الإعداد عن بُعد" في Podfile:

    pod 'Firebase/RemoteConfig'
    
  2. أضِف ما يلي في أعلى ملف AppDelegate الخاص بتطبيقك:

    Swift

    ملاحظة: لا يتوفّر منتج Firebase هذا على أنظمة التشغيل macOS وMac Catalyst وwatchOS المستهدفة.
    import FirebaseRemoteConfig
    

    Objective-C

    ملاحظة: لا يتوفّر منتج Firebase هذا على أنظمة التشغيل macOS وMac Catalyst وwatchOS المستهدفة.
    @import FirebaseRemoteConfig;
    
  3. في ملف 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];
    
  4. في ViewController.m أو ملف تنفيذ آخر يستخدمه تطبيقك، أضِف الرمز التالي لاسترجاع قيم "الإعداد عن بُعد" وتفعيلها:

    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);
      }
    }];
    
  5. لإيقاف "مراقبة الأداء" في وحدة تحكُّم Firebase، أنشِئ معلَمة perf_disable في مشروع تطبيقك، ثم اضبط قيمتها على true.

    في حال ضبط القيمة perf_disable على false، ستظل ميزة "مراقبة الأداء" مفعّلة.

إيقاف جمع البيانات التلقائي أو المخصَّص بشكل منفصل

يمكنك إجراء بعض التغييرات على الرمز الموضّح أعلاه وفي وحدة تحكُّم Firebase للسماح لك بإيقاف جميع عمليات المراقبة التلقائية (الغير الجاهزة) بشكلٍ منفصل عن المراقبة المخصّصة.

  1. أضِف الرمز التالي إلى عبارات 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];
    
  2. أكمِل ما يلي في "وحدة تحكُّم Firebase":

    • لإيقاف جميع عمليات المراقبة التلقائية (غير المتوفّرة)، أنشِئ مَعلمة perf_disable_auto في مشروع تطبيقك، ثم اضبط قيمتها على true.
    • لإيقاف جميع التتبُّع المخصّص، أنشِئ معلَمة perf_disable_manual في مشروع تطبيقك، ثم اضبط قيمتها على true.