nativescript-social-share-v2
为 NativeScript 处理社交分享小部件的回调。
npm i --save nativescript-social-share-v2

NativeScript 社交分享(版本 2)

此版本的 NativeScript 社交分享类似于现有版本,但它包括获取 iOS 和 Android 的完成回调的能力!

这对于捕捉分析特别有用,例如,确定所使用的分享方法。

或者用户返回应用后触发工作流程。

安装

从项目的根目录运行以下命令

ns plugin add nativescript-social-share-v2

入门

要使用社交分享模块,您必须首先 require() 它。在 require() 模块后,您有权访问其 API。

// ------------ JavaScript ------------------
var SocialShare = require("nativescript-social-share-v2");

// ------------- TypeScript ------------------
import * as SocialShare from "nativescript-social-share-v2";

API

shareImage(ImageSource image, [可选] String subject)

shareImage() 方法期望一个 ImageSource 对象。下面的代码从应用中加载一张图片,并使用它调用分享小部件

// ------------ JavaScript ------------------
var SocialShare = require("@nativescript/social-share");
var imageSourceModule = require("@nativescript/core");

var image = imageSourceModule.fromFile("~/path/to/myImage.jpg");
SocialShare.shareImage(image);

// ------------- TypeScript ------------------
import * as SocialShare from "@nativescript/social-share";
import { ImageSource } from "@nativescript/core";

let image = ImageSource.fromFile("~/path/to/myImage.jpg");
SocialShare.shareImage(image).then(result => {
// Callback result.
console.log(result.completed); // Boolean - Did the user share?
console.log(result.activityType); // String/null - Sharing Method.

}).catch(err => {
// There was a catastrophe...
console.log(err);
})

您可以可选地提供一个第二个参数来配置 Android 上的主题

SocialShare.shareImage(image, "How would you like to share this image?").then(result => {
// Callback result.
console.log(result.completed); // Boolean - Did the user share?
console.log(result.activityType); // String/null - Sharing Method.

}).catch(err => {
// There was a catastrophe...
console.log(err);
})

shareText(String text, [可选] String subject)

shareText() 方法期望一个简单的字符串

SocialShare.shareText('I love NativeScript!');

shareImage() 类似,您可以可选地向 shareText() 传递第二个参数来配置 Android 上的主题

SocialShare.shareText('I love NativeScript!', 'How would you like to share this text?');

这同样返回一个承诺,是可迭代的,因此回调结果可以以与 shareImage 示例相同的方式捕获。

shareUrl(String url, String text, [可选] String subject)

shareUrl() 方法期望一个 URL 和一个字符串。

SocialShare.shareUrl('https://www.nativescript.org/', 'Home of NativeScript');

您可以可选地向 shareUrl() 传递第二个参数来配置 Android 上的主题

SocialShare.shareUrl('https://www.nativescript.org/', 'Home of NativeScript', 'How would you like to share this url?');

这同样返回一个承诺,是可迭代的,因此回调结果可以以与 shareImage 示例相同的方式捕获。

安全

如果您在此软件包中发现安全漏洞,请向 Bespoke Technology Labs 发送电子邮件至 [email protected]。所有安全漏洞都将得到及时解决。您可以在此处查看我们的完整安全策略。

许可

NativeScript Social Share V2 库采用 Apache 2.0 许可协议 许可。

鸣谢

  • @LewisSmallwood - Bespoke Technology Labs
  • @NativeScript - NativeScript 社区