File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 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" />
Original file line number Diff line number Diff 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.' ,
You can’t perform that action at this time.
0 commit comments