diff --git a/android/src/main/java/com/uiwjs/react/wechat/RNWechatModule.java b/android/src/main/java/com/uiwjs/react/wechat/RNWechatModule.java index 4321dbb..1fae15e 100644 --- a/android/src/main/java/com/uiwjs/react/wechat/RNWechatModule.java +++ b/android/src/main/java/com/uiwjs/react/wechat/RNWechatModule.java @@ -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()); + } + } + } diff --git a/example/App.js b/example/App.js index 016cbdb..7e29eaa 100644 --- a/example/App.js +++ b/example/App.js @@ -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 ( @@ -27,6 +29,7 @@ export default class App extends Component { 当前微信的版本{isWXAppSupportApi ? '支持' : '不支持'} OpenApi + {version} diff --git a/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json b/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json index 118c98f..8121323 100644 --- a/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json @@ -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 } -} \ No newline at end of file +} diff --git a/index.d.ts b/index.d.ts index 8eefa85..fd9e78b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -10,9 +10,13 @@ export function registerApp(appid: string, universalLink: string): void; * 检查微信是否已被用户安装 * 微信已安装返回 `true`,未安装返回 `false`。 */ -export function isWXAppInstalled(): Promise; +export function isWXAppInstalled(): Promise; /** * 判断当前微信的版本是否支持 OpenApi * 支持返回 true,不支持返回 false */ -export function isWXAppSupportApi(): Promise; \ No newline at end of file +export function isWXAppSupportApi(): Promise; +/** + * 获取当前微信SDK的版本号 + */ +export function getApiVersion(): Promise; \ No newline at end of file diff --git a/index.js b/index.js index 0c012db..88c68e7 100644 --- a/index.js +++ b/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(); + } } diff --git a/ios/RNWechat.m b/ios/RNWechat.m index 81db1e3..f292c07 100644 --- a/ios/RNWechat.m +++ b/ios/RNWechat.m @@ -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