Ionic 2社交分享
问题描述:
我想在我的Ionic 2应用程序中“分享用户统计信息”。首先,我做了截图,然后我要与社会共享插件分享..Ionic 2社交分享
这是我的代码:
public shareStats(): void {
// Take a screenshot and get temporary file URI
Screenshot.URI(100)
.then((img) => {
this.platform.ready().then(() => {
let message: string = 'Message';
let subject: string = 'Stats';
let file = img;
let link = 'https://www.example.com';
SocialSharing.share(message, subject, file, link);
});
}, (err) => {
let prompt = this.alertCtrl.create({
title: 'Fallo',
subTitle: err,
buttons: ['Aceptar']
});
prompt.present();
console.log(err);
});
}
嗯,截图插件看起来做工精细,但我不在将社交分享代码添加到其中后知道发生了什么。因为我的设备没有打开最终的共享选项窗口。
总之,我需要做截图并在社交网络上分享。但我不知道我做错了什么,因为我无法通过作为cordova插件进行调试,只能在移动设备上运行。
这让我有点噪音的什么我送作为参数:let file = img;
因为我不知道它包含什么或什么样的数据,这是IMG返回我Screenshot.URI
,因为我不能对它进行调试移动设备。
感谢这么多提前!
伊万。
答
我解决了它:
public shareStats(): void {
this.platform.ready().then(() => {
// Take a screenshot and get temporary file URI
Screenshot.URI(100)
.then((res) => {
var options = {
message: this.SHARE_OPTIONS_MESSAGE,
subject: '', // fi. for email
files: [res.URI], // an array of filenames either locally or remotely
url: this.SHARE_OPTIONS_URL,
chooserTitle: this.SHARE_OPTIONS_CHOOSER_TITLE // Android only
}
SocialSharing.shareWithOptions(options)
.then(() => {
this.showSuccessShareMsg();
})
.catch((err) => {
this.showErrorShareMsg(err);
});
}, (err) => {
});
});
}