Posts

Post not yet marked as solved
2 Replies
1.7k Views
I was playing around with Mailkit. I wanted to extract some info, and show a notification when an email arrives. I copied some code that looked alright for notifications and added it to the defailt MailKit template. I ran it, enabled the extension, sent myself an email and.... Mail app crashes I restart the Mail app, and it instantly crashes on launch. I try to comment out the notification code that i added, compile it and restart the Mail app, and it still crashes. Any help for getting my Mail app back to work would be appreciated! Here is the exact code that made this happen. Don't run it locally unless you want your Mail app to no longer work. import MailKit import UserNotifications class MessageActionHandler: NSObject, MEMessageActionHandler {   static let shared = MessageActionHandler()       func decideAction(for message: MEMessage, completionHandler: @escaping (MEMessageActionDecision?) -> Void) {     // The action to take on the message, if any.     var action: MEMessageActionDecision? = nil           // Check if the subject of the message contains the word Mars.     // If it does, specify an action to set the background color to red.     if message.subject.contains("Mars") {       action = MEMessageActionDecision.action(.setBackgroundColor(.red))     }           let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)     var content = UNMutableNotificationContent()      content.title = "Message1"          content.subtitle = "subtitle"          content.body = "body"          content.sound = UNNotificationSound.default          var request = UNNotificationRequest(identifier: UUID().uuidString , content: content, trigger: trigger)          UNUserNotificationCenter.current().add(request)           // Always call the completion handler, passing the action     // to take, or nil if there's no action.     completionHandler(action)   } }
Posted Last updated
.