I am trying to open Apple’s Mail app from my application and I am running this code:
let mailURL = URL(string: "message://")!
if UIApplication.shared.canOpenURL(mailURL) {
UIApplication.shared.open(mailURL, options: [:], completionHandler: nil)
}
However, UIApplication.shared.canOpenURL(mailURL)
line returns false. This code actually working well on my other application but not working on this. Do you have any ideas what is the reason for this issue?
edit: I tried to run this both in the simulator and real device.
edit: using Xcode 12.5.1, Big Sur 11.6
2
Answers
Use
mailto
for the URL’s protocol, notmessage
.Example:
For security reasons, Apple doesn’t allow you to open URLs with arbitrary schemes, only those that you have registered to (so when they review your code they can figure out what applications you are checking for and reject you. Checking for mail is fine because everyone has that).
But Apple wouldn’t allow you to check if my app is installed on a device.