Ionic socialSharing 插件无法在 iOS 上运行
Ionic socialSharing plugin not working on iOS
Ionic social sharing plugin 无法处理 iOS。错误响应 returns 'not available'。在 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 有一些怪癖。
首先让我们看看您的错误是什么意思。根据their docs:
If Facebook is not installed, the errorcallback will be invoked with message '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,也是根据docs,讲的shareVia
函数怪癖:
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.
这首先意味着,使用此shareVia
功能,您只能分享到facebook、twitter、sinaweibo和tencentweibo(无论最后2个是什么)
其次,这意味着您需要在 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, .....)
})
}
Ionic social sharing plugin 无法处理 iOS。错误响应 returns 'not available'。在 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 有一些怪癖。
首先让我们看看您的错误是什么意思。根据their docs:
If Facebook is not installed, the errorcallback will be invoked with message '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,也是根据docs,讲的shareVia
函数怪癖:
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.
这首先意味着,使用此shareVia
功能,您只能分享到facebook、twitter、sinaweibo和tencentweibo(无论最后2个是什么)
其次,这意味着您需要在 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, .....)
})
}