React Native 轻松集成分享功能(iOS 篇)
产品一直催我在 RN 项目中添加分享功能,一直没找到合适的库,今天让我看到了一个插件分享给大家。
在集成插件之前,需要在各大开放平台上成功注册应用,并通过审核(支持 3 个可选的主流平台)。支持的平台如下:
第一步 安装:
在你的项目路径下执行命令:
npm install jshare-react-native --save
npm install jcore-react-native --save
react-native link
第二步:配置
配置 info.plist
在 info.plist 文件中添加如下键值对
<key>LSApplicationQueriesSchemes</key>
<array>
<!-- 微信 URL Scheme 白名单-->
<string>wechat</string>
<string>weixin</string>
<!-- 新浪微博 URL Scheme 白名单-->
<string>sinaweibohd</string>
<string>sinaweibo</string>
<string>sinaweibosso</string>
<string>weibosdk</string>
<string>weibosdk2.5</string>
<!-- QQ、Qzone URL Scheme 白名单-->
<string>mqqapi</string>
<string>mqq</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqqconnect</string>
<string>mqqopensdkdataline</string>
<string>mqqopensdkgrouptribeshare</string>
<string>mqqopensdkfriend</string>
<string>mqqopensdkapi</string>
<string>mqqopensdkapiV2</string>
<string>mqqopensdkapiV3</string>
<string>mqqopensdkapiV4</string>
<string>mqzoneopensdk</string>
<string>wtloginmqq</string>
<string>wtloginmqq2</string>
<string>mqqwpa</string>
<string>mqzone</string>
<string>mqzonev2</string>
<string>mqzoneshare</string>
<string>wtloginqzone</string>
<string>mqzonewx</string>
<string>mqzoneopensdkapiV2</string>
<string>mqzoneopensdkapi19</string>
<string>mqzoneopensdkapi</string>
<string>mqqbrowser</string>
<string>mttbrowser</string>
</array>
添加 URL Types
各个平台的 URL Schemes 格式说明:
| 平台 | 格式 | 举例 |
|---|---|---|
| 微信 | 微信 appKey | wxa2ea563906227379 |
| 需添加:“tencent” + 腾讯 QQ 互联应用 appID | 如 appID 为:1105864531 URL Schemes 值为:tencent1105864531 |
|
| 新浪微博 | “wb”+新浪 appKey | 如 appKey 为:727232518 URL Schemes 值为: wb727232518 |
URL Types 设置
要是实现跳转还需要在 Xcode 工程目录中的 [TARGETS] -> [Info] 中设置:

HTTPS 设置
Apple 将从2017年开始执行 ATS(App Transport Security),所有进行审核的应用中网络请求全部支持 HTTPS,届时以下配置将会失效,请提前做好准备。
目前 JSHARE 支持不存在新浪微博客户端情况下的网页分享,但是由于新浪微博的 api 尚未针对 https 做优化所以需要针对新浪的做对应的 https 设置。在 JSHARE 中是默认关闭新浪微博的网页端分享的,如需使用这个功能则需要在 JSHARELaunchConfig 类的实例中将 isSupportWebSina 属性设置为 YES。
以iOS10 SDK 编译的工程会默认以 SSL 安全协议进行网络传输,即 HTTPS,如果依然使用 HTTP 协议请求网络会报系统异常并中断请求。目前可用如下这种方式保持用 HTTP 进行网络连接:
在 info.plist 中加入安全域名白名单(右键 info.plist 用 source code 打开)
<key>NSAppTransportSecurity</key>
<dict>
<!-- 配置允许 http 的任意网络 End-->
<key>NSExceptionDomains</key>
<dict>
<!-- 集成新浪微博对应的 HTTP 白名单-->
<key>sina.com.cn</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>sinaimg.cn</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>sinajs.cn</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>sina.cn</key>
<dict>
<!-- 适配 iOS10 -->
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>weibo.cn</key>
<dict>
<!-- 适配 iOS10 -->
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>weibo.com</key>
<dict>
<!-- 适配 iOS10 -->
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<!-- 新浪微博-->
</dict>
</dict>
第三步:Usage 使用
import JShareModule from 'jshare-react-native';
JShareModule.setup(param) // iOS 需要调用初始化函数, parm 这个参数
,需要填入应用注册信息,详情可以参考 API 文档
成功初始化后,就可以调用分享接口,我们先要构造消息对象,然后再调用 share()
//
// platformString:'wechat_session' / 微信好友(会话)
// 'wechat_timeLine' / 微信朋友圈
// 'wechat_favourite' / 微信收藏
// 'qq' / QQ 好友
// 'qzone' / QQ 空间
// 'sina_weibo' / 新浪微博
// 'sina_weibo_contact'/ 新浪微博联系人
//
//
// textMessage =
// {
// type: 'text'
// platform: platformString // 分享到指定平台
// text: String
// imagePath: // 选填,新浪微博本地图片地址,其他平台没有这个字段(iOS 不支持这个字段)
// }
//
// imageMessage =
// {
// type: 'image'
// platform: platformString // 分享到指定平台
// imagePath: String // 本地图片路径 imagePath, imageUrl imageArray 必须三选一
// text: String // 选填
// imageUrl: String // 网络图片地址,必须以 http 或 https 开头,imagePath, imageUrl imageArray 必须三选一 (iOS 不支持这个字段)
// imageArray: [String] // (选填: 分享到 Qzone 才提供这个字段) 如果需要分享多张图片需要这个参数,数组中问题图片路径 imagePath, imageUrl imageArray 必须三选一
// }
//
// videoMessage =
// {
// type: 'video'
// platform: platformString // 分享到指定平台
// title: String // 选填
// url: String // 视频跳转页面 url
// text: String // 选填
// imagePath: String // 选填,缩略图,本地图片路径
//
// videoUrl: String // QQ 空间本地视频 (iOS 不支持这个字段)
// }
//
// audioMessage =
// {
// type: 'audio'
// platform: platformString // 分享到指定平台
// musicUrl: String //必填 点击直接播放的 url
// url: String //选填,点击跳转的 url
// imagePath: String //选填,缩略图,本地图片路径,imagePath,imageUrl 必须二选一
// imageUrl: String // 选填,网络图片路径,imagePath, imageUrl 必须二选一
// title: String // 选填
// text: String // 选填
// }
//
// fileMessage =
// {
// type: 'file'
// platform: platformString // 分享到指定平台
// path: String // 必填,文件路径
// fileExt: String // 必填,文件类型后缀
// tile: String
// }
//
// emoticonMessage =
// {
// type: 'emoticon'
// platform: platformString // 分享到指定平台
// imagePath: String // 必填,本地图片路径
// }
//
// appMessage =
// {
// type: 'app' // wechat_favourite 不支持
// platform: platformString // 分享到指定平台
// url: String // 点击跳转 url
// extInfo: String // 选填 第三方应用自定义数据
// path: String // 选填 对应 app 数据文件
// title: String // 选填
// text: String // 选填
// }
//
// {
// type: 'link'
// platform: platformString // 分享到指定平台
// url: String // 必填,网页 url
// imagePath: String // 选填,本地图片路径 imagePath,imageUrl 必须二选一
// imageUrl: String // 选填,网络图片地址 imagePath imageUrl 必须二选一 (iOS 不支持)
// title: String // 选填
// text: String // 选填
// }
// 消息分享可以分享如上的类型,不同消息需要构建不同的消息对象
// 当前支持 文字、图片、音频、视频、文件、链接、app、表情
JShareModule.share(message, successCallback, failCallback)
示例代码(分享文本到微信好友)
var shareParam = {
platform: "wechat_session",
type: "text",
text: "JShare test text"
};
shareParam.imagePath = this.state.path // this.state.path 是本地图片的路径
JShareModule.share(shareParam, (result) => {
console.log("share succeed, result: " + result);
}, (error) => {
console.log("share failed, map: " + error);
});
到此我们已经成功集成了分享功能,其他的 API 使用建议参考 文档
作者:HuminiOS - 极光推送
原文:React Native 轻松集成分享功能(iOS 篇)
知乎专栏:极光日报
React Native 轻松集成分享功能(iOS 篇)的更多相关文章
- React Native 轻松集成分享功能(Android 篇)
关于推送的集成请参考这篇文章,关于统计的集成请参考这篇文章,本篇文章将引导你集成分享功能. 在集成插件之前,需要在各大开放平台上成功注册应用,并通过审核(支持 3 个可选的主流平台).支持的平台如下: ...
- React Native 轻松集成统计功能(iOS 篇)
最近产品让我加上数据统计功能,刚好极光官方支持数据统计 支持了 React Native 版本 第一步 安装: 在你的项目路径下执行命令: npm install janalytics-react-n ...
- React Native 轻松集成统计功能(Android 篇)
关于推送的集成请参考这篇文章,本篇文章将引导你集成统计功能,只需要简单的三个步骤就可以集成统计功能. 第一步 安装 在你的项目路径下执行命令: npm install janalytics-react ...
- React Native 手工搭建环境 之iOS篇
常识 React native 开发服务器 在开发时,我们的框架是这样的:  当正式发布进入到生产环境时,开发服务器上所有的js文件将会被编译成包的形式,直接嵌入到客户端内.这时,已经不再需要开发服 ...
- React Native之微信分享(iOS Android)
React Native之微信分享(iOS Android) 在使用React Native开发项目的时候,基本都会使用到微信好友或者微信朋友圈分享功能吧,那么今天我就带大家实现以下RN微信好友以及朋 ...
- React Native之通知栏消息提示(ios)
React Native之通知栏消息提示(ios) 一,需求分析与概述 详情请查看:React Native之通知栏消息提示(android) 二,极光推送注册与集成 2.1,注册 详情请查看:Rea ...
- Android中使用ShareSDK集成分享功能
引言 现在APP开发集成分享功能已经是非常普遍的需求了.其他集成分享技术我没有使用过,今天我就来介绍下使用ShareSDK来进行分享功能开发的一些基本步骤和注意点,帮助朋友们避免一些坑.好了 ...
- React Native之配置URL Scheme(iOS Android)
React Native之配置URL Scheme(iOS Android) 一,需求分析 1.1,需要在网站中打开/唤起app,或其他app中打开app,则需要设置URL Scheme.比如微信的是 ...
- 教你轻松在React Native中集成统计(umeng)的功能(最新版)
关于在react-native中快速集成umeng统计,网上的文章或者教程基本来自----贾鹏辉老师的文章http://www.devio.org/2017/09/03/React-Native-In ...
随机推荐
- 在word表格里打勾和打叉
打勾:在单元格里输入R,再将其字体设置为:Wingdings 2. 打叉:在单元格里输入T,再将其字体设置为:Wingdings 2.
- 在使用pydelicious时出现HTTP Error 500: Internal Server Error的错误的解决方法:
问题:在学习<集体智慧编程>的过程中,第二章中如果你遇到了pydelicious.PyDeliciousException: HTTP Error 500: Internal Server ...
- Flink 1.3.2 Standalone模式安装
一.依赖文件安装 1.1 JDK 参见博文:http://www.cnblogs.com/liugh/p/6623530.html 二.文件准备 2.1 文件名称 flink-1.3.2-bin-ha ...
- (转载)2016 CCF大数据与计算智能大赛 开源资料整理
本文转载自:http://blog.sina.com.cn/s/blog_5399b8660102wxks.html 2016 CCF 大数据与计算智能大赛已经落下帷幕,11个赛题由众多大神包揽奖项, ...
- 【转载】webstorm11(注册,激活,破解,码,一起支持正版,最新可用)(2016.11.16更新)
很多人都发现 http://idea.lanyus.com/ 不能激活了 很多帖子说的 http://15.idea.lanyus.com/ 之类都用不了了 最近封的厉害仅作测试 选择 License ...
- Form表单提交,Ajax请求,$http请求的区别
做过前端同学想必都避免不了要和后台server打交道.而以下这三种与后台交互的方式想必大家都不陌生. Form表单提交,Ajax请求,Angular的$http请求 以前一直搞不清楚什么时候应该用哪种 ...
- solr-geohsah 按照距离搜索分组
通过solr的domain-import,将mysql的数据通过查询,导入到solr中.java通过使用solrj,链接solr,调用domaininport,并将分页参数设置到domain-impo ...
- bat调用带参数存储过程
@bat调用sql文件 sqlplus user/pass@orcl @F:\factory.sql @将所有的存储过程封装在sql中 factory.sql:exec pro_factory(&am ...
- Spring4整合quartz2.2.3,quartz动态任务
Spring4整合quartz2.2.3,quartz动态任务 >>>>>>>>>>>>>>>>> ...
- ABP从入门到精通(6):快速重命名解决方案
SolutionRenamer SolutionRenamer 是一个解决方案快速重命名工具.经测试重命名一个全新asp.net zero core项目(ABP asp.net zero,.net c ...