I want to open the email app (from emulator) and send an email from there but when i click the button i'm getting this error below but the app is not crashing
The error:
iGrow Goals[41098:3002008] -canOpenURL: failed for URL: "message://" - error: "This app is not allowed to query for scheme message"
My function:
func sendEmail() {
// Converted to Swift 5.4 by Swiftify v5.4.24488
let mailURL = URL(string: "message://")
if let mailURL = mailURL {
if UIApplication.shared.canOpenURL(mailURL) {
UIApplication.shared.open(mailURL, options: [:], completionHandler: nil)
}
}
}
This does not work in the simulator, only on a real device.
Don't forget to configure your Info.plist and add entry to message under this key: LSApplicationQueriesSchemes , so you can query it with canOpenURL.
Example Info.plist file that whitelists the URl query schemes:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlegmail</string>
<string>mailto</string>
<string>instagram</string>
<string>message</string>
</array>
You can also consider to use the mailto schema
let mailURL = URL(string: "mailto://example@example.com")
To set the value for the LSApplicationQueriesSchemes key in XCode when editing Info.plist, use " Queried URL Schemes ":
When editing the Info.plist manually, use the LSApplicationQueriesSchemes key as Alexander pointed out above:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>message</string>
</array>
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.