Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set MSACCrashes userConfirmationHandler as documented by Microsoft #246

Merged
merged 1 commit into from
Jul 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion AppBox/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,38 @@ - (void)awakeFromNib{

//Init AppCenter
[[NSUserDefaults standardUserDefaults] registerDefaults: @{ @"NSApplicationCrashOnExceptions": @YES }];
// Setting userConfirmationHandler as documented on https://docs.microsoft.com/en-us/appcenter/sdk/crashes/macos#ask-for-the-users-consent-to-send-a-crash-log
[MSACCrashes setUserConfirmationHandler:^BOOL(NSArray<MSACErrorReport *> * _Nonnull errorReports)
{
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = @"Sorry about that!";
alert.informativeText = @"Do you want to send a crash report so we can fix the issue?";

[alert addButtonWithTitle:@"Always send"];
[alert addButtonWithTitle:@"Send"];
[alert addButtonWithTitle:@"Don't send"];
alert.alertStyle = NSAlertStyleWarning;

switch ([alert runModal])
{
case NSAlertFirstButtonReturn:
[MSACCrashes notifyWithUserConfirmation:MSACUserConfirmationAlways];
break;
case NSAlertSecondButtonReturn:
[MSACCrashes notifyWithUserConfirmation:MSACUserConfirmationSend];
break;
case NSAlertThirdButtonReturn:
[MSACCrashes notifyWithUserConfirmation:MSACUserConfirmationDontSend];
break;
default:
break;

}
return true; // Return true if the SDK should await user confirmation, otherwise return false.
}];

NSString *appCenter = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"AppCenter"];
[MSACAppCenter start:appCenter withServices: @[[MSACAnalytics class], [MSACCrashes class]]];
[MSACCrashes notifyWithUserConfirmation: MSACUserConfirmationAlways];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
Expand Down