feat: Add getApiVersion props.
This commit is contained in:
@@ -13,6 +13,7 @@ public class RNWechatModule extends ReactContextBaseJavaModule {
|
||||
private final ReactApplicationContext reactContext;
|
||||
private String appId;
|
||||
private IWXAPI api = null;
|
||||
private final static String NOT_REGISTERED = "registerApp required.";
|
||||
|
||||
public RNWechatModule(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
@@ -34,4 +35,17 @@ public class RNWechatModule extends ReactContextBaseJavaModule {
|
||||
promise.reject("-1", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getApiVersion(Promise promise) {
|
||||
try {
|
||||
if (api == null) {
|
||||
throw new Exception(NOT_REGISTERED);
|
||||
}
|
||||
promise.resolve(api.getWXAppSupportAPI());
|
||||
} catch (Exception e) {
|
||||
promise.reject("-1", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,16 +6,18 @@ export default class App extends Component {
|
||||
state = {
|
||||
isInstall: false,
|
||||
isWXAppSupportApi: false,
|
||||
version: null,
|
||||
};
|
||||
async componentDidMount() {
|
||||
const isInstall = await Wechat.isWXAppInstalled();
|
||||
const isWXAppSupportApi = await Wechat.isWXAppSupportApi();
|
||||
const version = await Wechat.getApiVersion();
|
||||
this.setState({
|
||||
isInstall, isWXAppSupportApi
|
||||
isInstall, isWXAppSupportApi, version
|
||||
});
|
||||
}
|
||||
render() {
|
||||
const { isInstall, isWXAppSupportApi } = this.state;
|
||||
const { isInstall, isWXAppSupportApi, version } = this.state;
|
||||
return (
|
||||
<SafeAreaView style={{ flex: 1 }}>
|
||||
<View style={styles.container}>
|
||||
@@ -27,6 +29,7 @@ export default class App extends Component {
|
||||
<Text style={styles.instructions}>
|
||||
当前微信的版本<Text style={{color: isWXAppSupportApi ? 'green' : 'red'}}>{isWXAppSupportApi ? '支持' : '不支持'}</Text> OpenApi
|
||||
</Text>
|
||||
<Text>{version}</Text>
|
||||
</Text>
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
|
@@ -2,37 +2,52 @@
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"scale" : "2x"
|
||||
"scale" : "2x",
|
||||
"size" : "20x20"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"scale" : "3x"
|
||||
"scale" : "3x",
|
||||
"size" : "20x20"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"scale" : "2x"
|
||||
"scale" : "2x",
|
||||
"size" : "29x29"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"scale" : "3x"
|
||||
"scale" : "3x",
|
||||
"size" : "29x29"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"scale" : "2x"
|
||||
"scale" : "2x",
|
||||
"size" : "40x40"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"scale" : "3x"
|
||||
"scale" : "3x",
|
||||
"size" : "40x40"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"scale" : "2x",
|
||||
"size" : "60x60"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"scale" : "3x",
|
||||
"size" : "60x60"
|
||||
},
|
||||
{
|
||||
"idiom" : "ios-marketing",
|
||||
"scale" : "1x",
|
||||
"size" : "1024x1024"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
8
index.d.ts
vendored
8
index.d.ts
vendored
@@ -10,9 +10,13 @@ export function registerApp(appid: string, universalLink: string): void;
|
||||
* 检查微信是否已被用户安装
|
||||
* 微信已安装返回 `true`,未安装返回 `false`。
|
||||
*/
|
||||
export function isWXAppInstalled(): Promise<Boolean>;
|
||||
export function isWXAppInstalled(): Promise<boolean>;
|
||||
/**
|
||||
* 判断当前微信的版本是否支持 OpenApi
|
||||
* 支持返回 true,不支持返回 false
|
||||
*/
|
||||
export function isWXAppSupportApi(): Promise<Boolean>;
|
||||
export function isWXAppSupportApi(): Promise<boolean>;
|
||||
/**
|
||||
* 获取当前微信SDK的版本号
|
||||
*/
|
||||
export function getApiVersion(): Promise<string>;
|
8
index.js
8
index.js
@@ -1,7 +1,5 @@
|
||||
import { NativeModules, Platform } from 'react-native';
|
||||
|
||||
// const { RNWechat } = NativeModules;
|
||||
|
||||
export default class Wechat {
|
||||
/**
|
||||
* 向微信注册应用
|
||||
@@ -28,4 +26,10 @@ export default class Wechat {
|
||||
static isWXAppSupportApi() {
|
||||
return NativeModules.RNWechat.isWXAppSupportApi();
|
||||
}
|
||||
/**
|
||||
* 获取当前微信SDK的版本号
|
||||
*/
|
||||
static getApiVersion() {
|
||||
return NativeModules.RNWechat.getApiVersion();
|
||||
}
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ RCT_REMAP_METHOD(registerApp, :(NSString *)appid :(NSString *)universalLink reso
|
||||
}
|
||||
|
||||
// 检查微信是否已被用户安装, 微信已安装返回YES,未安装返回NO。
|
||||
RCT_REMAP_METHOD(isWXAppInstalled, :(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) {
|
||||
RCT_EXPORT_METHOD(isWXAppInstalled: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||
if ([WXApi isWXAppInstalled]) {
|
||||
resolve(@YES);
|
||||
} else {
|
||||
@@ -63,7 +63,7 @@ RCT_REMAP_METHOD(isWXAppInstalled, :(RCTPromiseResolveBlock)resolve :(RCTPromise
|
||||
}
|
||||
|
||||
// 判断当前微信的版本是否支持OpenApi,支持返回YES,不支持返回NO。
|
||||
RCT_REMAP_METHOD(isWXAppSupportApi, resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||
RCT_EXPORT_METHOD(isWXAppSupportApi: (RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) {
|
||||
if ([WXApi isWXAppSupportApi]) {
|
||||
resolve(@YES);
|
||||
} else {
|
||||
@@ -71,4 +71,9 @@ RCT_REMAP_METHOD(isWXAppSupportApi, resolver:(RCTPromiseResolveBlock)resolve rej
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前微信SDK的版本号
|
||||
RCT_EXPORT_METHOD(getApiVersion: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||
resolve([WXApi getApiVersion]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user