应用程序完成启动后,应用程序中心崩溃报告确认消失

App Center crash report confirmation disappears after app finish launching

我正在 Objective-C 应用程序中实施 App Center SDK,我需要实施崩溃报告发送确认。 微软在他们的指南中提供的解决方案通常有效(https://docs.microsoft.com/en-us/appcenter/sdk/crashes/ios),但在我的应用程序中,在 application:didFinishLaunchingWithOptions: 方法执行完成后,出现主页视图(在启动期间,显示加载屏幕),关闭警报确认。

我尝试在 waitUntilDone 上使用 performSelectorOnMainThread:withObject:waitUntilDone 和 YES - 它不起作用。

如果我尝试以另一种方法(不是 application:didFinishLaunchingWithOptions:) 实现此警报 - 警报就不会出现。

UI 阻塞 "while" 循环(等待回答)导致崩溃。

这里是微软的默认解决方案,它并不像我想要的那样工作。

[MSCrashes setUserConfirmationHandler:(^(NSArray<MSErrorReport *> *errorReports) {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"crash" message:@"message" preferredStyle:UIAlertControllerStyleAlert];                                                    

    UIAlertAction* sendAction = [UIAlertAction actionWithTitle:@"Send"
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *action) {
                                                           [MSCrashes notifyWithUserConfirmation:MSUserConfirmationSend];
                                                       }];

    [alertController addAction:sendAction];
    alertController.preferredAction = sendAction;

    [alertController addAction:[UIAlertAction actionWithTitle:@"Always send"
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
                                                          [MSCrashes notifyWithUserConfirmation:MSUserConfirmationAlways];
                                                      }]];

    [alertController addAction:[UIAlertAction actionWithTitle:@"Don't send"
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
                                                          [MSCrashes notifyWithUserConfirmation:MSUserConfirmationDontSend];
                                                      }]];

    [self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
    return YES;
})]

我希望用户在发送或不发送报告之前能够考虑尽可能多的时间,但在应用程序完成启动并出现新的(应用程序主页)视图后警报消失。

没有人遇到过这个问题吗? 你是怎么解决的?

已解决。

我希望这对某人有所帮助。

[MSCrashes setUserConfirmationHandler:(^(NSArray<MSErrorReport *> *errorReports) {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"crash"
                                                                             message:@"message"
                                                                      preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* sendAction = [UIAlertAction actionWithTitle:@"Send"
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *action) {
                                                           [MSCrashes notifyWithUserConfirmation:MSUserConfirmationSend];
                                                           [self.window makeKeyAndVisible];
                                                       }];

    [alertController addAction:sendAction];
    alertController.preferredAction = sendAction;

    [alertController addAction:[UIAlertAction actionWithTitle:@"Always send"
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
                                                          [MSCrashes notifyWithUserConfirmation:MSUserConfirmationAlways];
                                                          [self.window makeKeyAndVisible];
                                                      }]];

    [alertController addAction:[UIAlertAction actionWithTitle:@"Don't send"
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
                                                          [MSCrashes notifyWithUserConfirmation:MSUserConfirmationDontSend];
                                                          [self.window makeKeyAndVisible];
                                                      }]];

    self.alertWindowForCrashReport = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.alertWindowForCrashReport.rootViewController = [[UIViewController alloc] init];
    [self.alertWindowForCrashReport makeKeyAndVisible];
    [self.alertWindowForCrashReport.rootViewController presentViewController:alertController animated:YES completion:nil];

    return YES; // Return YES if the SDK should await user confirmation, otherwise NO.
})];

现在我在新的 window 中创建警报,将 [self.alertWindowForCrashReport makeKeyAndVisible] 发送到这个新的 window 以进行警报,然后在每个操作处理程序中发送 [self.window makeKeyAndVisible] 到 main window.