Sending errors on iOS
To send your own error message, use the YMMYandexMetrica class and YMMYandexMetricaReporting protocol methods:
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.
NSError *firstError = [NSError errorWithDomain:@"com.yandex.error-a" code:12 userInfo:@{ YMMBacktraceErrorKey: NSThread.callStackReturnAddresses, NSLocalizedDescriptionKey: @"Error A" }]; [YMMYandexMetrica reportNSError:firstError onFailure:nil];
Copied to clipboard
let firstError = NSError(domain: "com.yandex.error-a", code: 12, userInfo: [ YMMBacktraceErrorKey: Thread.callStackReturnAddresses, NSLocalizedDescriptionKey: "Error A" ]) YMMYandexMetrica.report(nserror: firstError, onFailure: nil)
Copied to clipboard
Example with YMMError
If errors are sent using the YMMError class or the YMMErrorRepresentable protocol, they're grouped by the identifier ID.
YMMError *underlyingError = [YMMError errorWithIdentifier:@"Underlying YMMError"]; YMMError *error = [YMMError errorWithIdentifier:@"YMMError identifier" message:@"Another custom message" parameters:@{ @"foo": @"bar" } backtrace:NSThread.callStackReturnAddresses underlyingError:underlyingError]; [YMMYandexMetrica reportError:error onFailure:nil];
Copied to clipboard
let underlyingError = YMMError.init(identifier: "Underlying YMMError") let error = YMMError( identifier: "YMMError identifier", message: "Another custom message", parameters: [ "foo": "bar" ], backtrace: Thread.callStackReturnAddresses, underlyingError: underlyingError) YMMYandexMetrica.report(error: error, onFailure: nil)
Copied to clipboard
Don't use variable values as grouping IDs. Otherwise, the number of groups increases and it becomes difficult to analyze them.