[英]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.