Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic socialSharing plugin not working on iOS

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>
like image 685
Lasithds Avatar asked May 15 '18 12:05

Lasithds


1 Answers

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, .....)
  })
}
like image 174
Ivar Reukers Avatar answered Nov 01 '22 11:11

Ivar Reukers