简体   繁体   中英

IOS: can't open Apple's Mail app with URL

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

Use mailto for the URL's protocol, not message .

Example:

mailto://me@example.com

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM