Class

MXMetricManager

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

Declaration

class MXMetricManager : NSObject

Overview

The MXMetricManager shared object manages your subscription for receiving on-device daily metrics.

To receive metrics, call add(_:) with an object supporting the didReceive(_:) method of MXMetricManagerSubscriber. The system then sends a report as an array of MXMetricPayload objects at most once per day. The array contains the metrics from the past 24 hours and any previously undelivered daily reports.

class AppDelegate: UIResponder, UIApplicationDelegate, MXMetricManagerSubscriber {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
        let shared = MXMetricManager.shared
        shared.add(self)
        
        return true
    }

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

Topics

Getting the Shared Metrics Manager

class var shared: MXMetricManager

An object that returns the shared metrics manager instance.

Subscribing to Reports

func add(MXMetricManagerSubscriber)

Registers to receive a daily report of app metrics from the metrics manager.

func remove(MXMetricManagerSubscriber)

Unsubscribes from daily reports of app metrics.

protocol MXMetricManagerSubscriber

A protocol defining a method for receiving a daily metrics report.

Retrieving Previous Reports

var pastPayloads: [MXMetricPayload]

Returns an array of the daily metrics reports generated since the last allocation for the shared manager instance.

Creating Custom Metric Logs

class func makeLogHandle(category: String) -> OSLog

Returns a log handle used for writing custom metric events.

Relationships

Inherits From

Conforms To

See Also

Essentials

class MXMetricPayload

An object that encapsulates a daily metrics report.