Claus Jørgensen Claus Jørgensen - 6 months ago 21
Swift Question

Setting NSLocalizedRecoveryOptionsErrorKey as NSError UserInfo doesn't provide any recovery options

Attempting to set some custom buttons for

presentError
via.
NSLocalizedRecoveryOptionsErrorKey
isn't working. Only the standard "OK" button is displayed.

NSApp.presentError(NSError(domain: "", code: 0, userInfo: [
NSLocalizedRecoveryOptionsErrorKey: ["Foo", "Bar"]
]))


It also have no effect setting any of the other UserInfo keys.

Is this simply no longer supported on OS X 10.11 ?

Answer

enter image description here

NSError *error = [NSError errorWithDomain:@"MyCoolDomain" code:1 userInfo:@{
                          NSLocalizedDescriptionKey: @"Could Not Post Message",
                          NSLocalizedFailureReasonErrorKey: @"We could not reach the XING server. Your internet connection seems to be offline.",
                          NSLocalizedRecoverySuggestionErrorKey: @"You may try again when you are online again.",
                          NSLocalizedRecoveryOptionsErrorKey: @[@"Try again", @"Cancel"]
                      }];
    NSAlert *alert = [NSAlert alertWithError:error];
    alert.informativeText = [error.localizedFailureReason stringByAppendingFormat:@"\n\n%@", alert.informativeText];
    [alert beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse returnCode) {
    }];

Try this. source : https://github.com/Hotel-Reservation-Service/HRSCustomErrorHandling/issues/8

When I face issues like these, I go searching for other people's code / issues.