12

Ionic social sharing plugin not working on iOS. Error response returns 'not available'. On Android it works as expected. Am I doing anything wrong?

// share functions parse accepts 'app' parameter
this.socialSharing.canShareVia(app, this.property.heading, '', '', this.property.link).then(res => {
      this.socialSharing.shareVia(app, this.property.heading, '', '', this.property.link);
}).catch(res => {
      this.gApp.hideLoading();
      this.gApp.showAlert('error', res);
});

// app name is parsed from html
<a (click)="shareVia('facebook')">facebook</a>
...    
<a (click)="shareVia('viber')">viber</a>
Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
Lasithds
  • 2,161
  • 25
  • 39

1 Answers1

6

First of all you didn't share your entire function so I'm going to make some assumptions. According to their docs iOS has some quirks.

So first things first let's see what your error means. According to their docs:

If Facebook is not installed, the errorcallback will be invoked with message 'not available'

Conclusion: you either have the app not installed, or you're not using a prefix for iOS (read below)

Edit your config.xml and add the following:

    <platform name="ios">

        <!-- add this entry -->
        <config-file platform="ios" target="*-Info.plist" parent="LSApplicationQueriesSchemes">
            <array>
                <string>facebook</string>
                <!-- ...... -->
                <string>viber</string>
            </array>
        </config-file>
    </platform>

To solve earlier said Quirk, also according to the docs, talking about shareVia function quirks:

iOS: You are limited to 'com.apple.social.[facebook | twitter | sinaweibo | tencentweibo]'. If an app does not exist, the errorcallback is invoked and iOS shows a popup message asking the user to configure the app.

This first of all means that, with this shareVia function, you can only share to facebook, twitter, sinaweibo and tencentweibo (whatever those last 2 are)

Second of all it means that you need to add com.apple.social. before the app

Basically setting prefix = this.platform.is('ios') ? 'com.apple.social.' : ''; and then using

import { Platform } from '@ionic-angular';
...
shareVia(app) {
  // only prefix on ios
  let prefix = this.platform.is('ios') ? 'com.apple.social.' : '';

  // NOTE: canShareVia doesn't need the prefix!
  this.canShareVia(app, .....).then(() => {
    // shareVia *does* require the prefix on ios. 
    // This returns 'not available' if the first parameter provided doesn't match an *installed* app.
    this.shareVia(prefix + app, .....)
  })
}
Ivar Reukers
  • 7,560
  • 9
  • 56
  • 99
  • I added the query strings to the config file as explain. Whatsapp can be queried but still, facebook fails when parsing 'facebook' to the canShareVia method. @Ivaro18 – Lasithds May 28 '18 at 06:42
  • hmm maybe the prefix is required on `canShareVia`, not sure. Do you also have Facebook installed? – Ivar Reukers May 28 '18 at 07:32