首页 > 其他分享 >ionic2实现社会化分享Social Sharing

ionic2实现社会化分享Social Sharing

时间:2022-11-28 20:33:51浏览次数:86  
标签:Sharing image share ionic2 only Social message 分享 subject


Social Sharing插件:​​Social Sharing​

参考:​​phonegap/cordova开发中的分享功能​​

       在ionic2项目下,执行如下语句安装插件:

$ ionic plugin add cordova-plugin-x-socialsharing

使用如下(具体查看ionic2的文档ionic-native部分):

html

<button ion-item (click)="share('Message only')">message only</button>
<button ion-item (click)="share('Message and subject', 'The subject')">message and subject</button>
<button ion-item (click)="share(null, null, null, 'http://www.x-services.nl')">link only</button>
<button ion-item (click)="share('Message and link', null, null, 'http://www.x-services.nl')">message and link</button>
<button ion-item (click)="share(null, null, 'https://www.google.nl/images/srpr/logo4w.png', null)">image only</button>

<button ion-item (click)="share(null, 'Android filename', 'data:image/png;base64,R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmNlnibXdVqolmhcRQA7', null)">base64 image only</button>

<button ion-item (click)="share('Message and image', null, 'https://www.google.nl/images/srpr/logo4w.png', null)">message and image</button>
<button ion-item (click)="share('Message, image and link', null, 'https://www.google.nl/images/srpr/logo4w.png', 'http://www.x-services.nl')">message, image and link</button>
<button ion-item (click)="share('Message, subject, image and link', 'The subject', 'https://www.google.nl/images/srpr/logo4w.png', 'http://www.x-services.nl')">message, subject, image and link</button>

ts文件中的share方法:

import { SocialSharing } from 'ionic-native';
share(message, subject?, file?, url?) {
SocialSharing.share(message, subject, file, url).then(() => {
// Success!

}, (err) => {
// Error!
alert('错误:分享失败!' + err);
});
}


其中:


message表示分享的内容;

subject表示分享的话题、主题;

file表示分享的图片或文件;

url表示分享的链接。



标签:Sharing,image,share,ionic2,only,Social,message,分享,subject
From: https://blog.51cto.com/u_15894233/5893652

相关文章