【问题标题】:Ionic socialSharing plugin not working on iOSIonic socialSharing 插件无法在 iOS 上运行
【发布时间】:2018-10-25 07:13:46
【问题描述】:

Ionic social sharing plugin 不适用于 iOS。错误响应返回“不可用”。在 Android 上,它按预期工作。 我做错什么了吗?

// 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>

【问题讨论】:

    标签: cordova typescript ionic-framework ionic3 cordova-plugins


    【解决方案1】:

    首先,你没有分享你的整个功能,所以我要做出一些假设。根据他们的文档,iOS 有一些怪癖。

    所以首先让我们看看你的错误意味着什么。根据their docs:

    如果未安装 Facebook,则会调用错误回调并显示消息“不可用”

    结论:您要么没有安装应用程序,要么没有使用 iOS 前缀(请阅读下文)

    编辑您的config.xml 并添加以下内容:

        <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>
    

    解决前面说的Quirk,也照docs,说说shareVia函数的quirk:

    iOS:您仅限于 'com.apple.social.[facebook |推特 | 新浪微博 |腾讯微博]'。如果应用程序不存在,则 调用 errorcallback 并且 iOS 显示一条弹出消息询问用户 配置应用程序。

    这首先意味着,有了这个shareVia功能,你只能分享到facebook、twitter、新浪微博和腾讯微博(不管最后两个是什么)

    其次,这意味着您需要在app之前添加com.apple.social.

    基本设置prefix = this.platform.is('ios') ? 'com.apple.social.' : '';然后使用

    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, .....)
      })
    }
    

    【讨论】:

    • 我将查询字符串添加到配置文件中作为解释。可以查询 Whatsapp,但在将“facebook”解析为 canShareVia 方法时,facebook 仍然失败。 @Ivaro18
    • 嗯,canShareVia 可能需要前缀,不确定。你也安装了 Facebook 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 2020-09-09
    • 2019-04-13
    • 2019-07-17
    • 1970-01-01
    • 2023-03-03
    • 2019-09-03
    相关资源
    最近更新 更多