参考 https://github.com/jpush/jshare-react-native
react-native版本 0.62.0
- 安装组件
npm install jshare-react-native --save
如果没有jcore的话,需要安装jcore-react-native
npm install jcore-react-native --save
react-native 60以上autolink
- 切换到ios目录下执行pod install
cd ios && pod install
IOS端配置
- 在 Appdelegate.m 中插入代码
#import <RCTJShareModule.h>
// work in iOS(8.0)
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
[JSHAREService handleOpenUrl:url];
return YES;
}
// work in iOS(9_0)
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
[JSHAREService handleOpenUrl:url];
return YES;
}
// work in iOS(9_0,++)
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
[JSHAREService handleOpenUrl:url];
return YES;
}
- 添加 RCTJShareConfig.plist 文件到 XCode 中,在Xcode导航栏里直接New file选择Property List文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>appKey</key>
<string>xxxxxx</string>
<key>channel</key>
<string></string>
<key>advertisingId</key>
<string></string>
<key>isProduction</key>
<true/>
<key>wechatAppId</key>
<string>xxxxx</string>
<key>wechatAppSecret</key>
<string>xxxx</string>
<key>qqAppId</key>
<string>xxxx</string>
<key>qqAppKey</key>
<string>xxxxx</string>
<key>sinaWeiboAppKey</key>
<string>xxxx</string>
<key>sinaWeiboAppSecret</key>
<string>xxxx</string>
<key>sinaRedirectUri</key>
<string>http://www.antsnest.cn</string>
<key>facebookAppId</key>
<string></string>
<key>facebookDisplayName</key>
<string></string>
<key>isSupportWebSina</key>
<true/>
</dict>
</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>weibo