Search code examples
ioscordovasharewhatsappngcordova

SocialSharing-PhoneGap-Plugin canShareVia check whether WhatsApp is available


Before showing a "share via WhatsApp" button, I want to check whether this kind of sharing is possible.

I'm using SocialSharing-PhoneGap-Plugin with the paper-thin ngCordova wrapper.

As the "via" parameter of canShareVia is platform-dependent, I use following structure to determine the via parameter:

var viaByKeyAndPlatform = {
    facebook: {
        ios: 'com.apple.social.facebook',
        android: 'com.facebook.katana'
    },
    whatsapp: {
        ios: '??? ', // not working: com.apple.social.whatsapp
        android: 'com.whatsapp'
    },
    twitter: {
        ios: 'com.apple.social.twitter',
        android: 'com.twitter.android'
    }
};

// ... determine `via` parameter from parameters above

$cordovaSocialSharing.canShareVia(
    via, 'message', 'subject', null, 'http://example.com')

This is working for all these social networks on iOS and Android, except for WhatsApp on iOS.

Which parameter can I use for this? com.apple.social.whatsapp doesn't work unfortunately.


Solution

  • Just found in the docs, that parameter whatsapp should work, but for iOS9 a whitelisting is necessary for the whatsapp:// url.

    So I used whatsapp as via parameter and added following to the *-Info.plist file and it works like a charm. BTW the clipboard-hint needs the entry in the *-Info.plist as well. Without, the hint is not showing!

    <key>LSApplicationQueriesSchemes</key>
    <array>
    
      <!-- quite sure there are already other entries -->
    
      <string>whatsapp</string>
      <string>fb</string>
    </array>