I'm working a React Native (0.64.0) app in iOS and am trying to open a link. I'm running this app using Xcode 14 on the built-in iPhone 12 simulator. I have a onPressSendEmail
function that calls another function called OpenURLButton
like this:
const OpenURLButton = (url) => {
const handlePress = async () => {
// Checking if the link is supported for links with custom URL scheme.
const supported = await Linking.canOpenURL(url);
if (supported) {
// Opening the link with some app, if the URL scheme is "http" the web link should be opened
// by some browser in the mobile
await Linking.openURL(url);
} else {
Alert.alert(`Don't know how to open this URL: ${url}`);
}
};
handlePress();
}
onPressSendEmail = () => {
OpenURLButton(`mailto:?to=`);
}
It should just open their mail app like how mailto
functions on web.
I edited my Info.plist
like this to accept mailto protocol:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
<string>tel</string>
<string>telprompt</string>
</array>
But I still get this error coming from canOpenURL
: "-canOpenURL: failed for URL: "mailto:?to=" - error: "The operation couldn’t be completed. (OSStatus error -10814.)""
Similar questions on StackOverflow were usually about plugins or other apps and not "mailto". I've read that simulators can have trouble opening email links but I wanted to be certain something else wasn't wrong.
The issue was that I was using the iPhone simulator from Xcode.
mailto: links will not work in the simulator.