[英]Ionic socialSharing plugin not working on iOS
Ionic社交共享插件无法在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>
首先,你没有分享你的整个功能,所以我要做一些假设。 根据他们的文档,iOS有一些怪癖。
首先,让我们看看你的错误意味着什么。 根据他们的文件:
如果未安装Facebook,将调用errorcallback并显示消息“not available”
结论:您要么未安装应用程序,要么您没有使用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,还要根据文档 ,谈论shareVia
函数的怪癖:
iOS:你只限于'com.apple.social。[facebook | twitter | 新浪微博| 腾讯微博]”。 如果某个应用程序不存在,则会调用errorcallback,iOS会显示一条弹出消息,要求用户配置该应用程序。
这首先意味着,有了这个shareVia
功能,你只能分享到facebook,twitter,sinaweibo和tencentweibo(无论最后2个是什么)
其次,这意味着您需要添加com.apple.social.
在app
之前
基本上设置prefix = this.platform.is('ios') ? '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, .....)
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.