Xcode throw an error when i call the api finishExtendedLaunchMeasurement :
[General] Couldn't find persisted ALM/FrontBoard launch signpost id when finishing an ext launch task.
Error Domain=MXErrorDomain Code=5 "Internal failures happened inside of MetricKit." UserInfo={NSLocalizedDescription=Internal failures happened inside of MetricKit.}
The following code:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// create window
MXMetricManager.shared.add(self)
do {
let task_id = MXLaunchTaskID("1234.zmmm")
try MXMetricManager.extendLaunchMeasurement(forTaskID: task_id)
print("some task perform")
try MXMetricManager.finishExtendedLaunchMeasurement(forTaskID: task_id)
} catch {
print(error)
}
return true
}
how i can fix this problem?
CodePudding user response:
you should not call finishExtendedLaunchMeasurement here because the app is not launch completely there. just do it like this, or any other time you want, such as the first screen showed
dispatch_async(dispatch_get_main_queue(), ^{
if (@available(iOS 16.0, *)) {
[[MetricsManager shared] finishLaunchMeasurement];
}
});