Reputation: 1785
I want to "share user stats" in my Ionic 2 app. First, I do a screenshot, and then I want to share it with social share plugin..
This is my code:
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);
});
}
Well, Screenshot plugin appears to work fine, but i don't know what is happening after I added the social share code into it. Because my device do not open the tipically share options window.
In short, I need to do screenshot and share it on social networks. But I do not know what I'm doing wrong because I can not debug it by being a cordova plugin and running only on mobile devices.
It makes me a bit of noise what I'm sending as a parameter: let file = img;
Because I do not know what it contains or what kind of data this img is that returns me Screenshot.URI
, because I can not debug it with the mobile device.
Thank's so much in advance!
Ivan.
Upvotes: 0
Views: 639
Reputation: 1785
I solved it:
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) => {
});
});
}
Upvotes: 1