Using Expo to build a React Native App.
Code:
const primaryLiveUrl = "vnd.youtube://channel/channel_id/live";
const secondaryLiveUrl =
"https://www.youtube.com/channel/channel_id/live";
const thirdLiveUrl = "https://www.youtube.com/channel_id/streams";
const redirectToYoutube = useCallback(async () => {
const primarySupported = await Linking.canOpenURL(primaryLiveUrl);
const secondarySupported = await Linking.canOpenURL(secondaryLiveUrl);
const thirdSupported = await Linking.canOpenURL(thirdLiveUrl);
if (primarySupported) {
console.log("1");
Linking.openURL(primaryLiveUrl);
} else if (secondarySupported) {
console.log("2");
Linking.openURL(secondaryLiveUrl);
} else if (thirdSupported) {
console.log("3");
Linking.openURL(thirdLiveUrl);
} else {
Alert.alert(
"Technical Error",
"It seems like something went wrong when trying to connect. \n\n To connect, search on Youtube.",
[
{
text: "Cancel",
style: "cancel",
},
{ text: "OK" },
]
);
}
}, []);
When running this on Simulator, iOS: links to 2, Android Links to 1. The redirect works also when trying on actual device.
However:
When generating a build:
eas build -p android --profile preview
using the eas.json
"preview": {
"distribution": "internal",
"ios": {
"resourceClass": "m1-medium"
},
"android": {
"buildType": "apk"
}
},
The redirect doesn't work on APK. Clicking on button always triggers the Alert.