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