App crashes after inserting text in iMessage app extension

Hello everyone,

I am currently developing an iMessage app extension using SwiftUI, and I'm experiencing a crash after successfully inserting text into the conversation. I've checked the console, and it prints "Text inserted successfully" before the crash occurs. However, I cannot find the cause of the crash, and I would appreciate any help in identifying and resolving the issue.

Here's the relevant code snippet for inserting text into the conversation:

private func insertMessage(withText text: String) {
    self.activeConversation?.insertText(text, completionHandler: { error in
        if let error = error {
            print("Error inserting text: \(error)")
        } else {
            print("Text inserted successfully")
        }
    })
}

Additionally I am getting a crash report which I will attach bellow:

If anyone has encountered a similar issue or has any suggestions, please let me know.

Thank you in advance for your help!

Replies

Are you running on the simulator?

If so, that's perfectly normal behaviour - remember your code is running mostly as a callback. From a brief look that's the same behaviour I've experienced for years - your code is terminated by Messages.

Does it work on device?