Contents

MXMetricManager

The shared object that registers you to receive metrics, creates logs for custom metrics, and gives access to past reports.

Declaration

class MXMetricManager

Overview

The MXMetricManager shared object manages your subscription for receiving on-device daily metrics. It receives daily metric reports when the device your app is installed on is running iOS 13 and later or macOS 26 and later.

MetricKit starts accumulating reports for your app after calling shared for the first time. To receive the reports, call add(_:) with an object that adopts the MXMetricManagerSubscriber protocol. The system delivers metric reports at most once per day per metric source, and diagnostic reports immediately in iOS 15 and later and macOS 12 and later. Some metrics originate from different system sources and arrive in a separate payload, so your app may receive more than one metric payload per day. The reports contain the metrics from the past 24 hours and any previously undelivered daily reports. To pause receiving reports, call remove(_:).

Calls to add a subscriber and to receive reports are safe to use in performance-sensitive code, such as during app launch.

The following example shows a class that subscribes to and receives MetricKit reports.

class AppMetrics: NSObject, MXMetricManagerSubscriber {
    func receiveReports() {
       let manager = MXMetricManager.shared
       manager.add(self)
    }

    func pauseReports() {
       let manager = MXMetricManager.shared
       manager.remove(self)
    }

    // Receive daily metrics.
    func didReceive(_ payloads: [MXMetricPayload]) {
       // Process metrics.
    }

    // Receive diagnostics immediately when available.
    func didReceive(_ payloads: [MXDiagnosticPayload]) {
       // Process diagnostics.
    }
}

Topics

Getting the shared metrics manager

Subscribing to reports

Retrieving previous reports

Creating custom metric logs

Measuring an extended launch

See Also

Metric and diagnostic reports