Skip to content

Commit 8bbbbaa

Browse files
committed
feat(Android): Add isWXAppInstalled/isWXAppSupportApi props.
1 parent 0ee0690 commit 8bbbbaa

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ https://uiwjs.github.io/react-native-wechat/apple-app-site-association
5454

5555
</details>
5656

57+
<details>
58+
<summary>iOS: -canOpenURL: failed for URL: "weixin://".</summary>
59+
60+
> ```
61+
> -canOpenURL: failed for URL: "weixin://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
62+
> ```
63+
64+
</details>
65+
5766
<details>
5867
<summary>iOS: RCTBridge required dispatch_sync to load RCTDevLoadingView.</summary>
5968

android/src/main/java/com/uiwjs/react/wechat/RNWechatModule.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public String getName() {
2929
public void registerApp(String appid, Promise promise) {
3030
try {
3131
this.appId = appid;
32-
api = WXAPIFactory.createWXAPI(reactContext.getApplicationContext(), appid, true);
32+
api = WXAPIFactory.createWXAPI(reactContext.getApplicationContext(), null, false);
3333
promise.resolve(api.registerApp(appid));
3434
} catch (Exception e) {
3535
promise.reject("-1", e.getMessage());
@@ -47,5 +47,29 @@ public void getApiVersion(Promise promise) {
4747
promise.reject("-1", e.getMessage());
4848
}
4949
}
50+
@ReactMethod
51+
public void isWXAppInstalled(Promise promise) {
52+
try {
53+
if (api == null) {
54+
throw new Exception(NOT_REGISTERED);
55+
}
56+
promise.resolve(api.isWXAppInstalled());
57+
} catch (Exception e) {
58+
promise.reject("-1", e.getMessage());
59+
}
60+
}
61+
62+
@ReactMethod
63+
public void isWXAppSupportApi(Promise promise) {
64+
try {
65+
if (api == null) {
66+
throw new Exception(NOT_REGISTERED);
67+
}
68+
int wxSdkVersion = api.getWXAppSupportAPI();
69+
promise.resolve(wxSdkVersion);
70+
} catch (Exception e) {
71+
promise.reject("-1", e.getMessage());
72+
}
73+
}
5074

5175
}

example/App.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ export default class App extends Component {
99
version: null,
1010
};
1111
async componentDidMount() {
12-
const isInstall = await Wechat.isWXAppInstalled();
13-
const isWXAppSupportApi = await Wechat.isWXAppSupportApi();
14-
const version = await Wechat.getApiVersion();
15-
this.setState({
16-
isInstall, isWXAppSupportApi, version
17-
});
12+
try {
13+
const reg = await Wechat.registerApp('wxd930ea5d5a258f4f');
14+
console.log('reg:', reg);
15+
const isInstall = await Wechat.isWXAppInstalled();
16+
const isWXAppSupportApi = await Wechat.isWXAppSupportApi();
17+
const version = await Wechat.getApiVersion();
18+
console.log('version:', version)
19+
this.setState({
20+
isInstall, isWXAppSupportApi, version
21+
});
22+
} catch (error) {
23+
console.log('error>', error);
24+
}
1825
}
1926
render() {
2027
const { isInstall, isWXAppSupportApi, version } = this.state;
@@ -29,7 +36,7 @@ export default class App extends Component {
2936
<Text style={styles.instructions}>
3037
当前微信的版本<Text style={{color: isWXAppSupportApi ? 'green' : 'red'}}>{isWXAppSupportApi ? '支持' : '不支持'}</Text> OpenApi
3138
</Text>
32-
<Text>{version}</Text>
39+
<Text> - v{version}</Text>
3340
</Text>
3441
</View>
3542
</SafeAreaView>

0 commit comments

Comments
 (0)