Framework Swift

What is MetricKit?

What’s MetricKit?

MetricKit in a new framework, introduced in iOS 13 (WWDC2019), with which it is intended to gather information (metrics) about battery behavior and application performance. For a registered application, reports on the behavior of said application will be received once a day as a general rule.


Battery metrics include, among other parameters:

  • The state of the mobile network.
  • The transfers through the internet.
  • The use of the CPU.
  • The use of the GPU.
  • The energy used to display the application on the screen.
  • The use of device location functions.


From the point of view of performance, metrics are obtained, for example, on:

  • The time it takes for the application to open (launch time).
  • The response of the application with user interaction.
  • The amount of time the application is active.
  • The use of memory and disk.


In order to receive metric reports, we need to add a subscription to MXMetricManager (for example in the AppDelegate class):

class AppDelegate: UIResponder, UIApplicationDelegate, MXMetricManagerSubscriber {

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

        return true

    func applicationWillTerminate(_ application: UIApplication) {

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

The didReceive method receives an array that contains the information of the last 24 hours (and of all that information that could not be received previously).

comments powered by Disqus

Related Posts

In mobile application development, along with native development platforms (iOS and Android), there are others, called hybrids, that allow developing applications for multiple platforms while maintaining a common code base: PhoneGap, Ionic, React Native, Xamarin and from recently, Flutter.

Data access Nowadays,for data access most mobile applications have an internal database (Core Data, Realm …) to store information, which can then be used, for example, if the application does not have an internet connection.

Checking Internet status in an app With iOS 12, Apple has introduced Network, a framework that includes the NWPathMonitor class.