- SDK Version: 40
- Platforms(Android/iOS/web/all): Android and iOS
Hello. I’m using the code extract below to open a specific page/id/username on Facebook, Instagram, and Twitter - first trying the app with the relevant scheme URL, and then the website if it fails.
It’s ‘kind of’ working on both Android and iOS - but sometimes the social media app doesn’t open even if it’s installed and the user is logged in, and the website opens instead, and often Facebook goes to the user’s own timeline rather than the specific page I want.
The three scheme URLs I’m using are:
fb://page?id=000000000000000
instagram://user?username=USERNAME
twitter://user?id=00000000
Am I doing anything obviously wrong?
import * as Linking from "expo-linking";
import * as WebBrowser from "expo-web-browser";
const handleAppOrWeb = async (appURL, webURL) => {
try {
const isApp = await Linking.canOpenURL(appURL);
console.log(isApp);
if (isApp) {
await Linking.openURL(appURL);
} else {
await WebBrowser.openBrowserAsync(webURL);
}
} catch (error) {
console.error(error);
}
};
I’ve got the following in my app.json file for iOS (nothing for Android).
"infoPlist": {
"UIBackgroundModes": ["audio"],
"LSApplicationQueriesSchemes": ["fb", "instagram", "twitter"]
}