Crash Reporting User Consent for iOS
This page explains the usage of user consent for iOS crash reports and the needed APIs to implement it.
Suppose you want your users' confirmation before sending a crash report to Instabug. In that case, the Instabug SDK exposes a callback awaiting each user's confirmation before sending any crash/error data to Instabug.
This callback function instructs Instabug to await user confirmation before sending crash reports. It is designed to enhance end-user privacy and control by allowing them to approve or decline the submission of crash reports, ensuring a more transparent and user-centric experience.
This callback applies to fatal errors (crashes) and out-of-memory (OOM) reports, force restarts, and excludes app hangs and non-fatal errors.
If no response is received within a 2-minute window, the callback triggers a timeout mechanism, preventing the automatic crash report sending.
Example Usage
CrashReporting.onWillSendCrashReportHandler = { crashType, completionHandler in
let crashTypeAsString: String
switch (crashType) {
case .crash:
crashTypeAsString = "Fatal Crash"
case .forceRestart:
crashTypeAsString = "User termination Crash"
case .OOM:
crashTypeAsString = "OOM Crash"
@unknown default:
fatalError()
}
let message = "Are You Sure Want to send Crash! for crash type: \(crashTypeAsString)"
let alert = UIAlertController(title: "Crash Consent", message: message, preferredStyle: .alert)
let yesButton = UIAlertAction(title: "Yes", style: .default, handler: { _ in
completionHandler?(.accept);
})
alert.addAction(yesButton)
let noButton = UIAlertAction(title: "No", style: .default, handler: { _ in
completionHandler?(.reject);
})
alert.addAction(noButton)
let rootViewController = UIApplication.shared.keyWindow?.rootViewController
rootViewController?.present(alert, animated: true)
}
IBGCrashReporting.onWillSendCrashReportHandler = ^(IBGCrashType crashType, IBGCrashReportConsentReplyHandler completionHandler) {
NSString *crashTypeAsString;
switch (crashType) {
case IBGCrashTypeCrash:
crashTypeAsString = @"Fatal Crash";
break;
case IBGCrashTypeForceRestart:
crashTypeAsString = @"User termination Crash";
break;
case IBGCrashTypeOOM:
crashTypeAsString = @"OOM Crash";
break;
}
NSString *message = [NSString stringWithFormat:@"Are You Sure Want to send Crash! for crash type: %@", crashTypeAsString];
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:@"Crash Consent"
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* yesButton = [UIAlertAction
actionWithTitle:@"Yes"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
completionHandler(IBGCrashReportConsentAccept);
}];
[alert addAction:yesButton];
UIAlertAction* noButton = [UIAlertAction
actionWithTitle:@"No"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
completionHandler(IBGCrashReportConsentReject);
}];
[alert addAction:noButton];
UIViewController *rootViewController = [UIApplication.sharedApplication.keyWindow rootViewController];
[rootViewController presentViewController:alert animated:YES completion:nil];
};
Minimum SDK Version
The minumum SDK version required to support user consent is
v12.7.0
Updated 4 months ago