GSepetadelis
GSepetadelis

Reputation: 300

failed for URL: "message://" - error: "This app is not allowed to query for scheme message"

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)
        }
    }
}

Upvotes: 2

Views: 4254

Answers (2)

SBlincov
SBlincov

Reputation: 381

To set the value for the LSApplicationQueriesSchemes key in XCode when editing Info.plist, use "Queried URL Schemes": Info.plist screenshot from XCode

When editing the Info.plist manually, use the LSApplicationQueriesSchemes key as Alexander pointed out above:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>message</string>
</array>

Upvotes: 0

Alexander G
Alexander G

Reputation: 276

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>

Info.plist

You can also consider to use the mailto schema

let mailURL = URL(string: "mailto://[email protected]")

Upvotes: 6

Related Questions