Problem with expo-linking on iOS simulator

  1. SDK Version: 39
  2. Platforms(Android/iOS/web/all): iOS

mailto: and tel: protocols fails on iOS simulator using expo-linking

import * as Linking from 'expo-linking';

	_pressCall=(phone_number)=>{
		const url='tel:' + phone_number.replace(/[^0-9\+]+/g, '');
		return Linking.openURL(url);
	}
	
	_pressEmail=(email)=>{
		const url='mailto:' + email;
		return Linking.openURL(url);
	}

Hey @caminoninja, this is actually expected behavior as the iOS Simulator does not have the Mail or Phone app available. Messages is available which is why the sms: scheme works. The RN docs have a note about this (well only tel:): https://reactnative.dev/docs/linking#openurl

This is a good example of why it’s a good practice to use canOpenUrl to check if the system can open a url before calling openUrl.

Cheers,
Adam

Oh …didn’t read the React Native note. Sorry about that. And thanks a lot. That helped and explained everything. Will make a canOpenUrl tjeck first.

Best
Andy

Hey @adamjnav, when I read those docs I got the impression it was not a good idea to call canOpenUrl

If your app is linked against an earlier version of iOS but is running in iOS 9.0 or later, you can call this method up to 50 times. After reaching that limit, subsequent calls always return false. If the user reinstalls or upgrades the app, iOS resets the limit.

What is the benefit of calling canOpenUrl over calling openUrl and handling the promise rejection if it fails?

I suppose the question I have now is: what version of iOS is React Native/Expo SDK 39 linked against.

Yeah canOpenUrl looks like it has some unwanted limitations. I don’t know the version of the users but do know a lot of people use old iPhones.

So I think this might be the safer implementation.

async _pressCall(phone_number) {
	const url = phone_number.replace(/[^0-9\+]+/g, '');

	try {
		await Linking.openURL('tel:'.concat(url));
	}
	catch(err) {
		Clipboard.setString(url);

		Alert.alert(url, 'Phone number copied to clipboard.', [{text: 'OK'}]);
	}
}

Yes, I think that seems like a reasonable way to.handle the error. Adam, what do you think?

This will probably be an issue on iPads without SIM cards as well I guess.

Looks like they will drop support for iOS 10 in next version of the SDK (41).

So, the question is really if the only “benefit” is failure to open even if the App you are linking to is installed if you tried opening more than 50 times before you installed the App.

canOpenUrl is “reccommended” and not required according to the documentation. But it really seems like a bad idea.

Anyone knows about this for sure?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.