Skip to content

Commit 2bf5a4c

Browse files
authored
Fix whatsapp link (#1352)
1 parent b19d1f8 commit 2bf5a4c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

app/android/app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
xmlns:tools="http://schemas.android.com/tools"
44

55
>
6+
<queries>
7+
<intent>
8+
<action android:name="android.intent.action.VIEW" />
9+
<data android:scheme="whatsapp" />
10+
</intent>
11+
</queries>
12+
613
<uses-permission android:name="android.permission.INTERNET" />
714
<uses-permission android:name="android.permission.CAMERA" />
815
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" />

app/src/utils/referralShare.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,22 @@ export const shareViaWhatsApp = async (message: string): Promise<void> => {
6161
try {
6262
const url = `whatsapp://send?text=${encodeURIComponent(message)}`;
6363

64-
const canOpen = await Linking.canOpenURL(url);
64+
const schemeToCheck = Platform.OS === 'ios' ? 'whatsapp://' : url;
65+
66+
const canOpen = await Linking.canOpenURL(schemeToCheck);
6567
if (canOpen) {
6668
await Linking.openURL(url);
6769
} else {
70+
// openURL() works even if canOpenURL() returns false in android
71+
if (Platform.OS === 'android') {
72+
try {
73+
await Linking.openURL(url);
74+
return;
75+
} catch {
76+
//atleast we tried
77+
//fallthrough to show alert
78+
}
79+
}
6880
Alert.alert(
6981
'WhatsApp Not Installed',
7082
'Please install WhatsApp to share via this method, or use the Share button instead.',

0 commit comments

Comments
 (0)