Skip to content

Commit 0ee0690

Browse files
committed
feat: Add getApiVersion props.
1 parent 70405ec commit 0ee0690

File tree

6 files changed

+68
-23
lines changed

6 files changed

+68
-23
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class RNWechatModule extends ReactContextBaseJavaModule {
1313
private final ReactApplicationContext reactContext;
1414
private String appId;
1515
private IWXAPI api = null;
16+
private final static String NOT_REGISTERED = "registerApp required.";
1617

1718
public RNWechatModule(ReactApplicationContext reactContext) {
1819
super(reactContext);
@@ -34,4 +35,17 @@ public void registerApp(String appid, Promise promise) {
3435
promise.reject("-1", e.getMessage());
3536
}
3637
}
38+
39+
@ReactMethod
40+
public void getApiVersion(Promise promise) {
41+
try {
42+
if (api == null) {
43+
throw new Exception(NOT_REGISTERED);
44+
}
45+
promise.resolve(api.getWXAppSupportAPI());
46+
} catch (Exception e) {
47+
promise.reject("-1", e.getMessage());
48+
}
49+
}
50+
3751
}

example/App.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ export default class App extends Component {
66
state = {
77
isInstall: false,
88
isWXAppSupportApi: false,
9+
version: null,
910
};
1011
async componentDidMount() {
1112
const isInstall = await Wechat.isWXAppInstalled();
1213
const isWXAppSupportApi = await Wechat.isWXAppSupportApi();
14+
const version = await Wechat.getApiVersion();
1315
this.setState({
14-
isInstall, isWXAppSupportApi
16+
isInstall, isWXAppSupportApi, version
1517
});
1618
}
1719
render() {
18-
const { isInstall, isWXAppSupportApi } = this.state;
20+
const { isInstall, isWXAppSupportApi, version } = this.state;
1921
return (
2022
<SafeAreaView style={{ flex: 1 }}>
2123
<View style={styles.container}>
@@ -27,6 +29,7 @@ export default class App extends Component {
2729
<Text style={styles.instructions}>
2830
当前微信的版本<Text style={{color: isWXAppSupportApi ? 'green' : 'red'}}>{isWXAppSupportApi ? '支持' : '不支持'}</Text> OpenApi
2931
</Text>
32+
<Text>{version}</Text>
3033
</Text>
3134
</View>
3235
</SafeAreaView>

example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,52 @@
22
"images" : [
33
{
44
"idiom" : "iphone",
5-
"size" : "29x29",
6-
"scale" : "2x"
5+
"scale" : "2x",
6+
"size" : "20x20"
77
},
88
{
99
"idiom" : "iphone",
10-
"size" : "29x29",
11-
"scale" : "3x"
10+
"scale" : "3x",
11+
"size" : "20x20"
1212
},
1313
{
1414
"idiom" : "iphone",
15-
"size" : "40x40",
16-
"scale" : "2x"
15+
"scale" : "2x",
16+
"size" : "29x29"
1717
},
1818
{
1919
"idiom" : "iphone",
20-
"size" : "40x40",
21-
"scale" : "3x"
20+
"scale" : "3x",
21+
"size" : "29x29"
2222
},
2323
{
2424
"idiom" : "iphone",
25-
"size" : "60x60",
26-
"scale" : "2x"
25+
"scale" : "2x",
26+
"size" : "40x40"
2727
},
2828
{
2929
"idiom" : "iphone",
30-
"size" : "60x60",
31-
"scale" : "3x"
30+
"scale" : "3x",
31+
"size" : "40x40"
32+
},
33+
{
34+
"idiom" : "iphone",
35+
"scale" : "2x",
36+
"size" : "60x60"
37+
},
38+
{
39+
"idiom" : "iphone",
40+
"scale" : "3x",
41+
"size" : "60x60"
42+
},
43+
{
44+
"idiom" : "ios-marketing",
45+
"scale" : "1x",
46+
"size" : "1024x1024"
3247
}
3348
],
3449
"info" : {
35-
"version" : 1,
36-
"author" : "xcode"
50+
"author" : "xcode",
51+
"version" : 1
3752
}
38-
}
53+
}

index.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ export function registerApp(appid: string, universalLink: string): void;
1010
* 检查微信是否已被用户安装
1111
* 微信已安装返回 `true`,未安装返回 `false`。
1212
*/
13-
export function isWXAppInstalled(): Promise<Boolean>;
13+
export function isWXAppInstalled(): Promise<boolean>;
1414
/**
1515
* 判断当前微信的版本是否支持 OpenApi
1616
* 支持返回 true,不支持返回 false
1717
*/
18-
export function isWXAppSupportApi(): Promise<Boolean>;
18+
export function isWXAppSupportApi(): Promise<boolean>;
19+
/**
20+
* 获取当前微信SDK的版本号
21+
*/
22+
export function getApiVersion(): Promise<string>;

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { NativeModules, Platform } from 'react-native';
22

3-
// const { RNWechat } = NativeModules;
4-
53
export default class Wechat {
64
/**
75
* 向微信注册应用
@@ -28,4 +26,10 @@ export default class Wechat {
2826
static isWXAppSupportApi() {
2927
return NativeModules.RNWechat.isWXAppSupportApi();
3028
}
29+
/**
30+
* 获取当前微信SDK的版本号
31+
*/
32+
static getApiVersion() {
33+
return NativeModules.RNWechat.getApiVersion();
34+
}
3135
}

ios/RNWechat.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ + (BOOL)requiresMainQueueSetup {
5454
}
5555

5656
// 检查微信是否已被用户安装, 微信已安装返回YES,未安装返回NO。
57-
RCT_REMAP_METHOD(isWXAppInstalled, :(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) {
57+
RCT_EXPORT_METHOD(isWXAppInstalled: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
5858
if ([WXApi isWXAppInstalled]) {
5959
resolve(@YES);
6060
} else {
@@ -63,12 +63,17 @@ + (BOOL)requiresMainQueueSetup {
6363
}
6464

6565
// 判断当前微信的版本是否支持OpenApi,支持返回YES,不支持返回NO。
66-
RCT_REMAP_METHOD(isWXAppSupportApi, resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
66+
RCT_EXPORT_METHOD(isWXAppSupportApi: (RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) {
6767
if ([WXApi isWXAppSupportApi]) {
6868
resolve(@YES);
6969
} else {
7070
resolve(@NO);
7171
}
7272
}
7373

74+
// 获取当前微信SDK的版本号
75+
RCT_EXPORT_METHOD(getApiVersion: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
76+
resolve([WXApi getApiVersion]);
77+
}
78+
7479
@end

0 commit comments

Comments
 (0)