sandPitPilot
sandPitPilot

Reputation: 39

Understanding MetricKit...didRecieve?

I recently added MetricKit to my app, and I've done the research and think I understand how this works by using the documentation example. I've added the MetricManager shared object along with the require protocol. The way I read this in the documentation is that everyday (every ~24 hours) metrics will be provided by my app, but my question is, "How do I read the received metrics from the app in the Xcode Organizer?"

I have set up my app with the MetricKit object and instantiated it in the app delegate but I have never received any metrics for the past 6 months. I know that in the didRecieve(_ payloads: ) method I can send these payloads to another web server like Vapor or some other service, but Im still not understanding how the metrics gets to the Organizer. If I check the payload and print the payloads.dictionaryRepresentation() by using Simulate MetricKit Payload, the didRecieve is called as expected.

Do I just leave the didRecieve method empty if I just want the Metrics to show up in the Xcode Organizer for my app?? Is this automatic? Is it that simple?

Xcode 12.5 and Swift 5

My Metrics Object

import MetricKit

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

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

  func didReceive(_ payloads: [MXMetricPayload]) {

    //What goes here if I just want to see the metrics on Xcode Organizer for my app????
    //Do I just leave it blank and it will automatically get sent to the organizer for my app?
   
  }

  @available(iOS 14.0, *)
  func didReceive(_ payloads: [MXDiagnosticPayload]) {

   //Same issue here with the new Diagnostic Payload?  What do I put to display in the Organizer?

  }
}

In my AppDelegate

import UIKit
import MetricKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  let appMetrics = AppMetrics()

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

    appMetrics.receiveReports()
    return true
  }

  func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
    
  }

  func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
    
  }

  func applicationWillTerminate(_ application: UIApplication) {

    appMetrics.pauseReports()

  }

}

Upvotes: 1

Views: 2137

Answers (2)

BlueskyMed
BlueskyMed

Reputation: 1305

MetricKit default output to the Xcode Organizer pane is completely useless to the vast majority of iOS developers.

I have some 20 odd Apps in the Store at the moment, some modestly successful with downloads in the low thousands range each with tens or perhaps 100 uses a day. I see the activity because I implemented Flurry in them: https://developer.yahoo.com/flurry/docs/integrateflurry/ios/

Some of my apps have been selling in the Store for 4 years or more. Yet, all the various MetricKit reports in Xcode are all EMPTY!

After some considerable research, I found a disclosure that Apple only creates these "free, no code" reports to Xcode for Apps that have many thousands and up downloads and many hundreds of runs per day. Thus despite promoting MetricKit as a very useful tool to improve performance, engagement and thus profit, Apple is, by intention, excluding perhaps 98% of its developer and App Store pool.

Likewise, the Apple MetricKit alternative to the "no code" reports requires a developer to get an ISP-based server account, and create a Postgres or other sort of server App on their ISP to receive REST-type POSTs, and then write more code to store, parse and analyze the data streaming from their deployed apps. For small iOS development shops, this is a pretty big order.

For my two cents, actually $99.00 per year developer program fee, Apple should provide this sort of server service reconfigured for storage and reporting!

Upvotes: 0

sandPitPilot
sandPitPilot

Reputation: 39

After further research it appears the answer is that I only need to setup the MetricKit if I will be uploading my metrics to my own server or another sever. Apparently it should be automatic that app metrics are provided by apple to the Xcode Organizer every ~24 hours. For some reason I never received any metrics at all which caused me to think I was doing something wrong. Problem lies with Apple somewhere. So if Xcode Organizer Metrics continue not to show up, its best to set up metrics to an API and see them on there, such as Firebase Performance or SwiftInfo. Hope this helps others when researching this.

Here is a good reference: https://medium.com/expedia-group-tech/monitoring-app-performance-on-ios-7a48fb25cfc2

Upvotes: 1

Related Questions