首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Ionic 2社交分享

Ionic 2社交分享
EN

Stack Overflow用户
提问于 2017-02-28 03:15:48
回答 1查看 627关注 0票数 0

我想在我的Ionic 2应用程序中“分享用户数据”。首先,我做了一个截图,然后我想把它分享给社交分享插件。

这是我的代码:

代码语言:javascript
运行
复制
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);
            });
    }

Screenshot插件似乎工作得很好,但我不知道在我添加了社交分享代码后会发生什么。因为我的设备没有打开tipically options窗口。

简而言之,我需要截图并在社交网络上分享。但我不知道我做错了什么,因为我不能通过作为cordova插件来调试它,并且只能在移动设备上运行。

我发送的参数是:let file = img;,因为我不知道它包含什么,也不知道这个img返回给我的Screenshot.URI是什么类型的数据,因为我不能用移动设备调试它。

提前感谢了这么多!

伊万。

EN

回答 1

Stack Overflow用户

发布于 2017-02-28 05:26:59

我解决了这个问题:

代码语言:javascript
运行
复制
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) => {

                });
        });

    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42493968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档