update docs
This commit is contained in:
parent
e932574b8d
commit
21be889086
@ -63,7 +63,7 @@ dependencies {
|
||||
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
||||
//noinspection GradleDynamicVersion
|
||||
implementation "com.facebook.react:react-native"
|
||||
implementation group: 'com.tencent.mm.opensdk', name: 'wechat-sdk-android', version: '6.8.20'
|
||||
api group: 'com.tencent.mm.opensdk', name: 'wechat-sdk-android', version: '6.8.20'
|
||||
}
|
||||
|
||||
if (isNewArchitectureEnabled()) {
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
# Build Setup for Android
|
||||
|
||||
## 注意
|
||||
请根据本文档严格配置,否则会导致微信无法回调你的应用,例如授权登录后无法跳回 APP,或者小程序无法拉起 APP
|
||||
如果配置过程有不明白,可以查看 [样本工程](https://github.com/little-snow-fox/react-native-wechat-lib/tree/master/example)
|
||||
在样本工程里搜索 '**react-native-wechat-lib support**' 便可以找到所有需要添加配置的地方
|
||||
|
||||
Then update `MainActivity.java` or `MainApplication.java`:
|
||||
|
||||
## 注册模块
|
||||
添加到 `MainApplication.java` 或 `MainActivity.java`:
|
||||
```java
|
||||
import com.theweflex.react.WeChatPackage; // Add this line
|
||||
import com.wechatlib.WeChatLibPackage; // Add this line
|
||||
|
||||
@Override
|
||||
protected List<ReactPackage> getPackages() {
|
||||
@ -12,29 +16,26 @@ import com.theweflex.react.WeChatPackage; // Add this line
|
||||
List<ReactPackage> packages = new PackageList(this).getPackages();
|
||||
// Packages that cannot be autolinked yet can be added manually here, for example:
|
||||
// packages.add(new MyReactNativePackage());
|
||||
packages.add(new WeChatPackage()); // Add this line
|
||||
packages.add(new WeChatLibPackage()); // Add this line
|
||||
return packages;
|
||||
}
|
||||
```
|
||||
|
||||
**Integrating with login and share**
|
||||
|
||||
If you are going to integrate login or share functions, you need to
|
||||
create a package named 'wxapi' in your application package and a class
|
||||
named `WXEntryActivity` in it.
|
||||
|
||||
## 登录和分享回调
|
||||
如果您打算集成登录或共享功能,则需要这样做
|
||||
在应用程序包和类中创建名为 "wxapi" 的包, 命名为 WXEntryActivit
|
||||
```java
|
||||
package your.package.wxapi;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import com.theweflex.react.WeChatModule;
|
||||
import com.wechatlib.WeChatLibModule;
|
||||
|
||||
public class WXEntryActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
WeChatModule.handleIntent(getIntent());
|
||||
WeChatLibModule.handleIntent(getIntent());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,12 +35,12 @@ android_library(
|
||||
|
||||
android_build_config(
|
||||
name = "build_config",
|
||||
package = "org.bigbug.member.rnapp",
|
||||
package = "pro.aili.temporary",
|
||||
)
|
||||
|
||||
android_resource(
|
||||
name = "res",
|
||||
package = "org.bigbug.member.rnapp",
|
||||
package = "pro.aili.temporary",
|
||||
res = "src/main/res",
|
||||
)
|
||||
|
||||
|
||||
@ -135,7 +135,7 @@ android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
|
||||
defaultConfig {
|
||||
applicationId "org.bigbug.member.rnapp"
|
||||
applicationId "pro.aili.temporary"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 1
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
||||
* directory of this source tree.
|
||||
*/
|
||||
package org.bigbug.member.rnapp;
|
||||
package pro.aili.temporary;
|
||||
|
||||
import android.content.Context;
|
||||
import com.facebook.flipper.android.AndroidFlipperClient;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.bigbug.member.rnapp">
|
||||
package="pro.aili.temporary">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
@ -22,7 +22,21 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- react-native-wechat-lib support ( -->
|
||||
<activity
|
||||
android:name=".wxapi.WXEntryActivity"
|
||||
android:label="@string/app_name"
|
||||
android:exported="true"
|
||||
android:taskAffinity="pro.aili.temporary"
|
||||
android:launchMode="singleTask"
|
||||
/>
|
||||
<!-- ) -->
|
||||
</application>
|
||||
|
||||
<!-- react-native-wechat-lib support ( -->
|
||||
<queries>
|
||||
<package android:name="com.tencent.mm" />
|
||||
</queries>
|
||||
<!-- ) -->
|
||||
|
||||
</manifest>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package org.bigbug.member.rnapp;
|
||||
package pro.aili.temporary;
|
||||
|
||||
import com.facebook.react.ReactActivity;
|
||||
import com.facebook.react.ReactActivityDelegate;
|
||||
@ -1,4 +1,4 @@
|
||||
package org.bigbug.member.rnapp;
|
||||
package pro.aili.temporary;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
@ -9,9 +9,12 @@ import com.facebook.react.ReactNativeHost;
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import org.bigbug.member.rnapp.newarchitecture.MainApplicationReactNativeHost;
|
||||
import pro.aili.temporary.newarchitecture.MainApplicationReactNativeHost;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
// react-native-wechat-lib support (
|
||||
import com.wechatlib.WeChatLibPackage;
|
||||
// )
|
||||
|
||||
public class MainApplication extends Application implements ReactApplication {
|
||||
|
||||
@ -26,8 +29,12 @@ public class MainApplication extends Application implements ReactApplication {
|
||||
protected List<ReactPackage> getPackages() {
|
||||
@SuppressWarnings("UnnecessaryLocalVariable")
|
||||
List<ReactPackage> packages = new PackageList(this).getPackages();
|
||||
|
||||
// react-native-wechat-lib support (
|
||||
// Packages that cannot be autolinked yet can be added manually here, for example:
|
||||
// packages.add(new MyReactNativePackage());
|
||||
packages.add(new WeChatLibPackage());
|
||||
// )
|
||||
|
||||
return packages;
|
||||
}
|
||||
|
||||
@ -73,7 +80,7 @@ public class MainApplication extends Application implements ReactApplication {
|
||||
We use reflection here to pick up the class that initializes Flipper,
|
||||
since Flipper library is not available in release mode
|
||||
*/
|
||||
Class<?> aClass = Class.forName("org.bigbug.member.rnapp.ReactNativeFlipper");
|
||||
Class<?> aClass = Class.forName("pro.aili.temporary.ReactNativeFlipper");
|
||||
aClass
|
||||
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
|
||||
.invoke(null, context, reactInstanceManager);
|
||||
@ -1,4 +1,4 @@
|
||||
package org.bigbug.member.rnapp.newarchitecture;
|
||||
package pro.aili.temporary.newarchitecture;
|
||||
|
||||
import android.app.Application;
|
||||
import androidx.annotation.NonNull;
|
||||
@ -19,9 +19,9 @@ import com.facebook.react.fabric.CoreComponentsRegistry;
|
||||
import com.facebook.react.fabric.FabricJSIModuleProvider;
|
||||
import com.facebook.react.fabric.ReactNativeConfig;
|
||||
import com.facebook.react.uimanager.ViewManagerRegistry;
|
||||
import org.bigbug.member.rnapp.BuildConfig;
|
||||
import org.bigbug.member.rnapp.newarchitecture.components.MainComponentsRegistry;
|
||||
import org.bigbug.member.rnapp.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate;
|
||||
import pro.aili.temporary.BuildConfig;
|
||||
import pro.aili.temporary.newarchitecture.components.MainComponentsRegistry;
|
||||
import pro.aili.temporary.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package org.bigbug.member.rnapp.newarchitecture.components;
|
||||
package pro.aili.temporary.newarchitecture.components;
|
||||
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
@ -1,4 +1,4 @@
|
||||
package org.bigbug.member.rnapp.newarchitecture.modules;
|
||||
package pro.aili.temporary.newarchitecture.modules;
|
||||
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.react.ReactPackage;
|
||||
@ -0,0 +1,16 @@
|
||||
package pro.aili.temporary.wxapi;
|
||||
|
||||
// react-native-wechat-lib support (
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import com.wechatlib.WeChatLibModule;
|
||||
|
||||
public class WXEntryActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
WeChatLibModule.handleIntent(getIntent());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
// )
|
||||
@ -10,7 +10,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "18.1.0",
|
||||
"react-native": "0.70.6"
|
||||
"react-native": "0.70.6",
|
||||
"react-native-wechat-lib": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.12.9",
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import { StyleSheet, View, Text, Button, Alert } from 'react-native';
|
||||
import { getApiVersion, registerApp, openWXApp, sendAuthRequest } from 'react-native-wechat-lib';
|
||||
import { getApiVersion, registerApp, openWXApp, sendAuthRequest, shareText } from 'react-native-wechat-lib';
|
||||
|
||||
export default function App() {
|
||||
const [versionNumber, setVersionNumber] = React.useState<string | undefined>();
|
||||
|
||||
React.useEffect(() => {
|
||||
registerApp('wx48d112e107595c4f', 'universalLink').then((res) => {
|
||||
registerApp('wx7973caefdffba1b8', 'universalLink').then((res) => {
|
||||
console.log("registerApp: " + res)
|
||||
getApiVersion().then((num) => {
|
||||
console.log("test: " + num)
|
||||
@ -18,7 +18,7 @@ export default function App() {
|
||||
|
||||
}, []);
|
||||
|
||||
function login() {
|
||||
function onLogin() {
|
||||
sendAuthRequest('snsapi_userinfo', '')
|
||||
.then((response: any) => {
|
||||
// todo 登录 response.code
|
||||
@ -36,6 +36,13 @@ export default function App() {
|
||||
|
||||
}
|
||||
|
||||
function onShareText() {
|
||||
shareText({
|
||||
text: 'test content.',
|
||||
scene: 0
|
||||
}).then()
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.title}>Call wechat SDK demo</Text>
|
||||
@ -47,7 +54,10 @@ export default function App() {
|
||||
<Button title={'拉起微信'} onPress={() => { openWXApp().then() }} />
|
||||
</View>
|
||||
<View style={styles.button}>
|
||||
<Button title={'授权登录'} onPress={() => { login() }} />
|
||||
<Button title={'授权登录'} onPress={() => { onLogin() }} />
|
||||
</View>
|
||||
<View style={styles.button}>
|
||||
<Button title={'分享'} onPress={() => { onShareText() }} />
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user