最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Native Linking.canOpenURL() with WhatsApp call - Stack Overflow

programmeradmin3浏览0评论

I'm trying to create a link to start a conversation on whatsapp from my react native app, but the method Linking.canOpenURL() is allways retuning false...

My code is the following:

const url = `whatsapp://send?phone=${celNumber}`;
Linking.canOpenURL(url).then(supported => {
    if (supported) {
        Linking.openURL(url);
    } else {
        Alert.alert(
            'Alert',
            'WhatsApp is not installed',
        )
    }
});

If I try to put some other url like tel:${celNumber} it returns true, so I think there is some problem with whatsapp url and canOpenURL(), since the whatsapp url works with the method Linking.openURL()...

I'm trying to create a link to start a conversation on whatsapp from my react native app, but the method Linking.canOpenURL() is allways retuning false...

My code is the following:

const url = `whatsapp://send?phone=${celNumber}`;
Linking.canOpenURL(url).then(supported => {
    if (supported) {
        Linking.openURL(url);
    } else {
        Alert.alert(
            'Alert',
            'WhatsApp is not installed',
        )
    }
});

If I try to put some other url like tel:${celNumber} it returns true, so I think there is some problem with whatsapp url and canOpenURL(), since the whatsapp url works with the method Linking.openURL()...

Share Improve this question asked Mar 10, 2018 at 15:45 Marcelo Tardelli MagalhãesMarcelo Tardelli Magalhães 6572 gold badges7 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

I quess you are using iOS? Then you have to declared the URL’s scheme 'whatsapp' in your Info.plist file LSApplicationQueriesSchemes.

iOS9: canOpenURL returning false for WhatApp's url scheme

https://developer.apple./documentation/uikit/uiapplication/1622952-canopenurl

if lands there someone doing it with expo in 2024, here're the relevant expo doc (and ref).

Copying the example app.json config from the doc:

{
  "expo": {
    "ios": {
      "infoPlist": {
        "LSApplicationQueriesSchemes": ["whatsapp"]
      }
    }
  }
}
发布评论

评论列表(0)

  1. 暂无评论