react-native: Linking.openURL mailto / tel not working in iOS : 'Unable to open URL'

Description

When trying to call Linking.openURL() with a ‘mailto’ or ‘tel’ scheme not working in iOS. The error is ‘Unable to open URL’: Error: Unable to open URL: mailto:someone@gmail.com at promiseMethodWrapper (http://192.168.3.5:19000/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false:3880:45) at openURL (http://192.168.3.5:19000/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false:95294:81) Tested in iOS emulator and in TestFlight version.

React Native Version

0.71.8

Output of npx react-native info

info Fetching system and libraries information… System: OS: macOS 13.4 CPU: (8) arm64 Apple M1 Pro Memory: 153.05 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node Yarn: 1.22.18 - ~/.nvm/versions/node/v16.14.2/bin/yarn npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm Watchman: Not Found Managers: CocoaPods: 1.11.3 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3 Android SDK: API Levels: 29 Build Tools: 31.0.0, 32.0.0 System Images: android-29 | Google Play ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7784292 Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild Languages: Java: 1.8.0_202 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.8 => 0.71.8 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

I have an Expo project, and after updating to latest Expo / RN Linking.openURL constantly gives me this error. Even a simple code stopped working: <Text onPress={() => { Linking.openURL('mailto:billgates@gmail.com'); }}>Try linking!</Text> Tested in iOS emulator and in TestFlight version.

Snack, code example, screenshot, or link to a repository

https://github.com/akve/expo-linking-sample

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (1 by maintainers)

Most upvoted comments

I fixed it by replacing all spaces.

str.replace(/\s/g, '')

I fixed encoding subject and body:

    const encodedSubject = encodeURIComponent(subject);
    const encodedBody = encodeURIComponent(body);

    await Linking.openURL(
      `mailto:${recipient}?subject=${encodedSubject}&body=${encodedBody}`
    );

I have the same problem. On my old version (0.67.5) it was working but now I’ve got error Error: Unable to open URL: file:///private/var/containers/Bundle/Application/XXX/XX.app/tel:12131313%7D. Add file to LSApplicationQueriesSchemes in your Info.plist. but I have the same:

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>itms</string>
  <string>mailto</string>
  <string>tel</string>
</array>

The same issue, after updating from 0.70 to 0.71, because of empty space only on ios. 😢

This method may behave differently in a simulator e.g. “tel:” links are not able to be handled in the iOS simulator as there’s no access to the dialer app. think mailto is the same.