Sending errors on iOS
To send your own error message, use the YMMYandexMetrica
class and YMMYandexMetricaReporting
protocol methods:
+reportError:onFailure:
+reportError:options:onFailure:
+reportNSError:onFailure:
+reportNSError:options:onFailure:
Note
These methods are supported since AppMetrica SDK version 3.11.1.
To send error messages, you can use the standard NSError class, the simplified YMMError
class, or the YMMErrorRepresentable
protocol.
Example with NSError
If errors are sent using the NSError class, they're grouped by the domain domain and the code error code.
Objective-CSwift
NSError *firstError = [NSError errorWithDomain:@"io.appmetrica.error-a" code:12 userInfo:@{ AMABacktraceErrorKey: NSThread.callStackReturnAddresses, NSLocalizedDescriptionKey: @"Error A" }]; [[AMAAppMetricaCrashes crashes] reportNSError:firstError onFailure:nil];
let firstError = NSError(domain: "io.appmetrica.error-a", code: 12, userInfo: [ BacktraceErrorKey: Thread.callStackReturnAddresses, NSLocalizedDescriptionKey: "Error A" ]) AppMetricaCrashes.crashes().report(nserror: firstError)
Example with YMMError
If errors are sent using the
YMMError
class or theYMMErrorRepresentable
protocol, they're grouped by theidentifier
ID.Objective-CSwift
AMAError *underlyingError = [AMAError errorWithIdentifier:@"Underlying AMAError"]; AMAError *error = [AMAError errorWithIdentifier:@"AMAError identifier" message:@"Another custom message" parameters:@{ @"foo": @"bar" } backtrace:NSThread.callStackReturnAddresses underlyingError:underlyingError]; [[AMAAppMetricaCrashes crashes] reportError:error onFailure:nil];
let underlyingError = AppMetricaError(identifier: "Underlying AMAError") let error = AppMetricaError( identifier: "AMAError identifier", message: "Another custom message", parameters: [ "foo": "bar" ], backtrace: Thread.callStackReturnAddresses, underlyingError: underlyingError ) AppMetricaCrashes.crashes().report(error: error)
Don't use variable values as grouping IDs. Otherwise, the number of groups increases and it becomes difficult to analyze them.
If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.