MEComposeSessionHandler alert message not shown

When the mail extension invoke allowMessageSendForSession func, the error prompt did not show the error description. What am I missing?

Below is the code:

    enum ComposeSessionError: LocalizedError {

        case invalidRecipientDomain

        

        var errorDescription: String? {

            switch self {

            case .invalidRecipientDomain:

                return "example.com is not a valid recipient domain"

            }

        }

    }

    

    func allowMessageSendForSession(_ session: MEComposeSession) async throws {

        // Before Mail sends a message, your extension can validate the

        // contents of the compose session. If the message isn't ready to be

        // sent, throw an error.



        throw ComposeSessionError.invalidRecipientDomain

    }

The completion of allowMessageSendForSession() has changed recently. Pass an Error in the completion, see updated Apple docu at https://developer.apple.com/documentation/mailkit/mecomposesessionhandler/3824908-allowmessagesendforsession

The docu contains a code snippet:

enum ComposeSessionError: LocalizedError {
    case invalidRecipientDomain
    
    var errorDescription: String? {
        switch self {
        case .invalidRecipientDomain:
            return "example.com is not a valid recipient domain"
        }
    }
}

func allowMessageSendForSession(_ session: MEComposeSession, completion: @escaping (Error?) -> Void) {
    // Confirm none of the recipients use @example.com.
    if session.mailMessage.allRecipientAddresses.contains(where: { $0.hasSuffix("@example.com")}) {
        completion(ComposeSessionError.invalidRecipientDomain)
    } else {
        completion(nil)
    }
}

Hi Martijn,

I get the same issue as stephenlem on Xcode 13.1 and (13.2 beta 2). The error description is not showing in the dialogue, even when the example code is used. Could it be a bug?

Thanks for the response Martijn. Even with the updated code I am not getting the error description to show in the alert. I can definitely trigger the condition, so that's not the issue. It's just that the alert window that comes up doesn't have a description. It looks exactly like the screenshot at the top of this thread.

I've tried even adding 'failureReason', 'helpAnchor', and 'recoverSuggestion' properties to the error. None of them are getting picked up for some reason.

This is still broken in MacOS 12.2

still there on macOS 12.3 and 12.4 beta 1. FB9983235

MacOS 12.4 release still has this issue. Let's hope it will be fixed in MacOS 13.

MEComposeSessionHandler alert message not shown
 
 
Q