[Technical Questions] App Crashes When Trying to Send Email in iOS Simulator #162
-
In what area do you have a technical challenge?Xcode, Simulator & Previews DescriptionI am encountering an issue when attempting to use MFMailComposeViewController in my SwiftUI app running on the iOS Simulator. When trying to present the mail compose view via MailView, the app crashes with the following error messages: Since I am running the app on the iOS Simulator, it appears that mail functionality is not available. However, I would like to confirm whether there is a workaround to test this feature in the Simulator or if there is a recommended way to handle this scenario in code to prevent crashes. ReproductionBranch: [https://github.com/CS342/2025-CoughSync/tree/ReportShare]
Expected behaviorI expected the app to present the mail compose view or at least fail gracefully instead of crashing. If the Simulator does not support mail functionality, I would like guidance on how to handle this properly in code. Additional contextNo response Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@jennleww There is no workaround for the simulator; you need to use the check if a user can send a mail first and if it returns no you can not instantiate the compose view controller, see e.g.,: https://developer.apple.com/documentation/messageui/mfmailcomposeviewcontroller#Checking-the-availability-of-the-composition-interface Alternative is to launch the mail app, as we do in: Spezi Contact, but that also won't work in a way that you can test this, you will have to test this on a real device and/or after your PR has been merged and is deployed to TestFlight. |
Beta Was this translation helpful? Give feedback.
@jennleww There is no workaround for the simulator; you need to use the check if a user can send a mail first and if it returns no you can not instantiate the compose view controller, see e.g.,: https://developer.apple.com/documentation/messageui/mfmailcomposeviewcontroller#Checking-the-availability-of-the-composition-interface
Alternative is to launch the mail app, as we do in: Spezi Contact, but that also won't work in a way that you can test this, you will have to test this on a real device and/or after your PR has been merged and is deployed to TestFlight.