I'm trying to implement a mailto share link into my iOS application. But facing an issue when using mailto:
URL scheme.
I tried to use tel:+1234567890
URL scheme and it's working properly. I tried running the app on iOS 13 on a device (not simulator), and Mail app is currently installed with a mailbox configured.
Here is the code:
//let urlString = String("mailto:test@.example.com") EDITED
let urlString = String("mailto:test@example.com")
if let url = URL(string: urlString) {
if(UIApplication.shared.canOpenURL(url)){
print("ok")
}else{
print("not ok")
}
}
if let url = URL(string: urlString) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:])
}else{
UIApplication.shared.openURL(url)
}
}
UIApplication.shared.canOpenURL(url)
returns false
.
Here is the error returned by UIApplication.shared.open method:
2020-01-14 14:17:42.497160+0100 MIPMobile[28645:9005290] [default] Failed to open URL email+launcher://?url=mailto:test@.example.com: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=247, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}
I don't think that the problem occurred prior to iOS. Does anyone know the reason for this issue?
Thank for your help