友盟分享登录的react-native android模块,仅集成qq,微信,新浪微博,需要其它的自行参照代码集成。
npm install react-native-puti-umeng-share
- 自动安装:
```
//first
npm install react-native-puti-umeng-share --save
//then android可自行导包,IOS由于静态库创建有问题,则需要手动集成
react-native link
- IOS 集成
- 第一步 前往node_module里的react-native-puti-umeng-share 文件夹下的ios-umeng-lib拷贝到工程目录下,并添加到项目中;
!image
- 第二步 TARGET -> General -> Linked Frameworks and Libraries 添加 libsqlite3.tbd CoreGraphics.framework 系统库
- 第三步 在项目中的info.plist中加入应用白名单,右键info.plist选择source code打开(plist具体设置在Build Setting -> Packaging -> Info.plist File可获取plist路径) 请根据选择的平台对以下配置进行缩减:
`
`
- 第四步 设置 URL Scheme URL Scheme是通过系统找到并跳转对应app的设置,通过向项目中的info.plist文件中加入URL types可使用第三方平台所注册的appkey信息向系统注册你的app,当跳转到第三方应用授权或分享后,可直接跳转回你的app。
- 第五步 在入口文件AppDelegate.m下设置回调
`
#import
- (BOOL)application:(UIApplication )application openURL:(NSURL )url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
- (BOOL)application:(UIApplication )application openURL:(NSURL )url options:(NSDictionary
{
return [RCTLinkingManager application:application openURL:url options:options];
}
`
- Android配置:
`
//需要配置友盟APPKEY,否则分享不可用
android:value="友盟APPKEY" />
//微信配置
在包名目录下创建wxapi文件夹,新建一个名为WXEntryActivity的activity继承WXCallbackActivity。
并配置Android Manifest XML
android:exported="true"
android:launchMode="singleTop" />
android:launchMode="singleTask"
android:noHistory="true" >
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="orientation|keyboardHidden|screenSize"/>
android:configChanges="keyboardHidden|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:exported="false"
android:screenOrientation="portrait" >
android:exported="false"
android:windowSoftInputMode="adjustResize">
android:launchMode="singleTask"
android:name="com.sina.weibo.sdk.share.WbShareTransActivity">
`
- 使用:
`
import UMShare from 'react-native-puti-umeng-share'
//是否开启调试
UMShare.debug(true)
//设置微信参数
UMShare.setWeixin(id,secret)
//设置微信参数
UMShare.setQQZone(id,key)
//设置新浪微博参数
UMShare.setSinaWeibo(key,secret,url)
//分享。
UMShare.share({
platform: ${UMShare.QQ}&${UMShare.WEIXIN},//分享平台,调用分享面板则使用&拼接
type: UMeng.UMWeb, //分享类型
title: '我是分享标题',
url: 'https://www.baidu.com',
desc: '我是分享描述',
image: 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3867393576,1410529218&fm=27&gp=0.jpg'
},res=>{
if (res){
alert('分享成功')
}else{
alert('分享失败')
}
})
//登录
UMShare.login(UMShare.WEIXIN)
.then((data) => {
ToastAndroid.show(data, ToastAndroid.SHORT);
}).catch(e => {
ToastAndroid.show(e, ToastAndroid.SHORT);
})
UMShare.isInstall(UMShare.WEIXIN)
.then((isInstall) => {
if (!isInstall) Toast('微信未安装')
})
``