jshare-react-native集成流程及问题记录,包含微信、QQ授权登录

本文档详细介绍了如何在react-native 0.62.0项目中集成jshare-react-native,包括iOS和Android的配置步骤,如在AppDelegate.m中添加代码,配置Info.plist和URL Types,以及Android的build.gradle和AndroidManifest.xml修改。同时,记录了在集成过程中遇到的问题,如android端autolink导致的构造函数冲突和dex文件过大问题,并提供了解决方案。最后,给出了JS端调用JShare的API进行分享和授权登录的操作指南。
摘要由CSDN通过智能技术生成

参考 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
### 回答1: 在Vue中实现代码需要先安装Vue CLI并创建一个新的Vue项目。然后,在src目录下创建一个新的.vue文件,例如HelloWorld.vue。在该文件中,可以使用template、script和style标签来编写Vue组件的HTML、JavaScript和CSS代码。以下是一个示例: ``` <template> <div> <h1>{{ greeting }}</h1> <p>{{ message }}</p> </div> </template> <script> export default { data() { return { greeting: 'Hello', message: 'Welcome to my Vue app!' } } } </script> <style scoped> h1 { font-size: 3em; color: #42b983; } p { font-size: 1.5em; line-height: 1.5; } </style> ``` 然后,在App.vue文件中使用该组件: ``` <template> <div id="app"> <HelloWorld /> </div> </template> <script> import HelloWorld from './components/HelloWorld.vue' export default { name: 'App', components: { HelloWorld } } </script> ``` 最后,在main.js文件中挂载Vue实例: ``` import Vue from 'vue' import App from './App.vue' Vue.config.productionTip = false new Vue({ render: h => h(App), }).$mount('#app') ``` 这样就可以在Vue中实现代码了。 ### 回答2: 要在Vue中实现给定代码,可以按照以下步骤进行操作: 1. 创建一个Vue项目,包括Vue的安装和配置。 2. 在项目中创建一个Vue组件,命名为"Demo",并将其注册到Vue实例中。 3. 在Demo组件的模板中,使用HTML和Vue的语法来实现页面的结构和布局。 4. 在组件的数据部分,声明一个data属性,用于存储需要在页面中展示的数据。 5. 在created生命周期钩子函数中,使用axios或者vue-resource等工具发送HTTP请求,获取需要的数据,并将其赋值给data中声明的属性。 6. 在页面的相应位置,使用Vue的指令(例如v-for)遍历数据,并以合适的方式展示在页面上。 7. 如果需要,可以在Vue组件中定义一些方法,用于进行一些处理逻辑或者响应用户的操作。 8. 最后,将Demo组件渲染到Vue实例的页面中。 以上是大致的步骤,根据具体代码需求可能会有所调整和扩展。在实际实现过程中,可能会涉及到Vue的路由、状态管理、组件通信等方面的内容,需要根据具体情况进行处理。若需要更详细的指导,请提供具体的代码内容。 ### 回答3: 首先,在Vue中实现该代码,我们需要先创建一个Vue实例,并在实例中定义相关的数据和方法。 ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue Demo</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h1>{{ message }}</h1> <button @click="changeMessage">点击改变消息</button> </div> <script> const app = new Vue({ el: '#app', data: { message: 'Hello, Vue!' }, methods: { changeMessage() { this.message = '你好,Vue!'; } } }) </script> </body> </html> ``` 在这段代码中,我们引入了Vue.js库,在HTML页面中创建了一个id为"app"的div以渲染Vue实例。在Vue实例的定义中,我们声明了一个"data"对象来存储数据,其中包括一个名为"message"的属性,初始值为"Hello, Vue!"。同时,我们在methods中定义了一个名为"changeMessage"的方法,当点击"点击改变消息"按钮时,该方法会被调用,从而将message的值改为"你好,Vue!"。最后,通过`{{ message }}`将message的值动态显示在页面上。 这样,我们就在Vue中实现了提供的代码。当页面运行后,会显示"Hello, Vue!"和一个按钮。当点击按钮时,消息会被改变为"你好,Vue!"。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值