feat: Add openWXApp props.
This commit is contained in:
		@@ -47,6 +47,19 @@ public class RNWechatModule extends ReactContextBaseJavaModule {
 | 
				
			|||||||
            promise.reject("-1", e.getMessage());
 | 
					            promise.reject("-1", e.getMessage());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ReactMethod
 | 
				
			||||||
 | 
					    public void openWXApp(Promise promise) {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            if (api == null) {
 | 
				
			||||||
 | 
					                throw new Exception(NOT_REGISTERED);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            promise.resolve(api.openWXApp());
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            promise.reject("-1", e.getMessage());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @ReactMethod
 | 
					    @ReactMethod
 | 
				
			||||||
    public void isWXAppInstalled(Promise promise) {
 | 
					    public void isWXAppInstalled(Promise promise) {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
import React, { Component } from 'react';
 | 
					import React, { Component } from 'react';
 | 
				
			||||||
import { Platform, SafeAreaView, StyleSheet, Text, View } from 'react-native';
 | 
					import { Platform, Button, SafeAreaView, StyleSheet, Text, View } from 'react-native';
 | 
				
			||||||
import Wechat from '@uiw/react-native-wechat';
 | 
					import Wechat from '@uiw/react-native-wechat';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class App extends Component {
 | 
					export default class App extends Component {
 | 
				
			||||||
@@ -10,19 +10,26 @@ export default class App extends Component {
 | 
				
			|||||||
  };
 | 
					  };
 | 
				
			||||||
  async componentDidMount() {
 | 
					  async componentDidMount() {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      const reg = await Wechat.registerApp('wxd930ea5d5a258f4f');
 | 
					      const reg = await Wechat.registerApp('wx500b695a47bd364b', 'https://uiwjs.github.io/react-native-wechat/apple-app-site-association');
 | 
				
			||||||
      console.log('reg:', reg);
 | 
					 | 
				
			||||||
      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();
 | 
					      const version = await Wechat.getApiVersion();
 | 
				
			||||||
      console.log('version:', version)
 | 
					      console.log('version:', version);
 | 
				
			||||||
      this.setState({
 | 
					      this.setState({
 | 
				
			||||||
        isInstall, isWXAppSupportApi, version
 | 
					        isInstall,
 | 
				
			||||||
 | 
					        isWXAppSupportApi,
 | 
				
			||||||
 | 
					        version
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    } catch (error) {
 | 
					    } catch (error) {
 | 
				
			||||||
 | 
					      console.log('code>', error.code);
 | 
				
			||||||
 | 
					      console.log('message>', error.message);
 | 
				
			||||||
      console.log('error>', error);
 | 
					      console.log('error>', error);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  openWXApp = async () => {
 | 
				
			||||||
 | 
					    const isOpen = await Wechat.openWXApp();
 | 
				
			||||||
 | 
					    console.log('isOpen:', isOpen);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  render() {
 | 
					  render() {
 | 
				
			||||||
    const { isInstall, isWXAppSupportApi, version } = this.state;
 | 
					    const { isInstall, isWXAppSupportApi, version } = this.state;
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
@@ -31,13 +38,18 @@ export default class App extends Component {
 | 
				
			|||||||
          <Text style={styles.welcome}>☆Wechat Example☆</Text>
 | 
					          <Text style={styles.welcome}>☆Wechat Example☆</Text>
 | 
				
			||||||
          <Text>
 | 
					          <Text>
 | 
				
			||||||
            <Text style={styles.instructions}>
 | 
					            <Text style={styles.instructions}>
 | 
				
			||||||
              <Text style={{color: isInstall ? 'green' : 'red'}}>{isInstall ? '有' : '没有'}</Text>安装微信,
 | 
					              <Text style={{color: isInstall ? 'green' : 'red'}}>{isInstall ? '已经' : '没有'}</Text>安装微信,
 | 
				
			||||||
            </Text>
 | 
					            </Text>
 | 
				
			||||||
            <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> - v{version}</Text>
 | 
					            <Text> - v{version}</Text>
 | 
				
			||||||
          </Text>
 | 
					          </Text>
 | 
				
			||||||
 | 
					          <Button
 | 
				
			||||||
 | 
					            onPress={this.openWXApp}
 | 
				
			||||||
 | 
					            title="打开微信 APP"
 | 
				
			||||||
 | 
					            color="#841584"
 | 
				
			||||||
 | 
					          />
 | 
				
			||||||
        </View>
 | 
					        </View>
 | 
				
			||||||
      </SafeAreaView>
 | 
					      </SafeAreaView>
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
 | 
					<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
 | 
				
			||||||
    <device id="retina4_7" orientation="portrait" appearance="light"/>
 | 
					    <device id="retina4_7" orientation="portrait" appearance="light"/>
 | 
				
			||||||
    <dependencies>
 | 
					    <dependencies>
 | 
				
			||||||
        <deployment identifier="iOS"/>
 | 
					        <deployment identifier="iOS"/>
 | 
				
			||||||
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
 | 
					        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
 | 
				
			||||||
        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
 | 
					        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
 | 
				
			||||||
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
 | 
					        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
 | 
				
			||||||
    </dependencies>
 | 
					    </dependencies>
 | 
				
			||||||
@@ -22,7 +22,7 @@
 | 
				
			|||||||
                                <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
 | 
					                                <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
 | 
				
			||||||
                                <nil key="highlightedColor"/>
 | 
					                                <nil key="highlightedColor"/>
 | 
				
			||||||
                            </label>
 | 
					                            </label>
 | 
				
			||||||
                            <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="example" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
 | 
					                            <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Wechat 微信" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
 | 
				
			||||||
                                <rect key="frame" x="0.0" y="202" width="375" height="43"/>
 | 
					                                <rect key="frame" x="0.0" y="202" width="375" height="43"/>
 | 
				
			||||||
                                <fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
 | 
					                                <fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
 | 
				
			||||||
                                <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
 | 
					                                <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								index.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								index.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -13,9 +13,13 @@ export function registerApp(appid: string, universalLink: string): void;
 | 
				
			|||||||
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>;
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 打开微信,成功返回 `true`,不支持返回 失败返回 `false`
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export function openWXApp(): Promise<boolean>;
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 获取当前微信SDK的版本号
 | 
					 * 获取当前微信SDK的版本号
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								index.js
									
									
									
									
									
								
							@@ -6,7 +6,7 @@ export default class Wechat {
 | 
				
			|||||||
   * @param appid 通过微信开放平台,[获取appid](https://open.weixin.qq.com/)
 | 
					   * @param appid 通过微信开放平台,[获取appid](https://open.weixin.qq.com/)
 | 
				
			||||||
   * @param universalLink 参数在 iOS 中有效,Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。
 | 
					   * @param universalLink 参数在 iOS 中有效,Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  static registerApp(appid, universalLink) {
 | 
					  static registerApp(appid, universalLink = '') {
 | 
				
			||||||
    if (Platform.OS === 'ios') {
 | 
					    if (Platform.OS === 'ios') {
 | 
				
			||||||
      return NativeModules.RNWechat.registerApp(appid, universalLink);
 | 
					      return NativeModules.RNWechat.registerApp(appid, universalLink);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -21,11 +21,17 @@ export default class Wechat {
 | 
				
			|||||||
    return NativeModules.RNWechat.isWXAppInstalled();
 | 
					    return NativeModules.RNWechat.isWXAppInstalled();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * 判断当前微信的版本是否支持OpenApi,支持返回 true,不支持返回 false
 | 
					   * 判断当前微信的版本是否支持 OpenApi,支持返回 true,不支持返回 false
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  static isWXAppSupportApi() {
 | 
					  static isWXAppSupportApi() {
 | 
				
			||||||
    return NativeModules.RNWechat.isWXAppSupportApi();
 | 
					    return NativeModules.RNWechat.isWXAppSupportApi();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * 打开微信,成功返回 true,不支持返回 失败返回 false
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  static openWXApp() {
 | 
				
			||||||
 | 
					    return NativeModules.RNWechat.openWXApp();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * 获取当前微信SDK的版本号
 | 
					   * 获取当前微信SDK的版本号
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,10 @@ RCT_EXPORT_MODULE()
 | 
				
			|||||||
    self = [super init];
 | 
					    self = [super init];
 | 
				
			||||||
    if (self) {
 | 
					    if (self) {
 | 
				
			||||||
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:@"RCTOpenURLNotification" object:nil];
 | 
					        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:@"RCTOpenURLNotification" object:nil];
 | 
				
			||||||
 | 
					        // 在register之前打开log, 后续可以根据log排查问题
 | 
				
			||||||
 | 
					        [WXApi startLogByLevel:WXLogLevelDetail logBlock:^(NSString *log) {
 | 
				
			||||||
 | 
					            NSLog(@"WeChatSDK: %@", log);
 | 
				
			||||||
 | 
					        }];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return self;
 | 
					    return self;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -44,12 +48,12 @@ RCT_EXPORT_MODULE()
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 注册 appid
 | 
					// 注册 appid
 | 
				
			||||||
RCT_REMAP_METHOD(registerApp, :(NSString *)appid :(NSString *)universalLink resolver: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
 | 
					RCT_REMAP_METHOD(registerApp, appid:(NSString *)appid universalLink:(NSString*)universalLink resolver: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
 | 
				
			||||||
    if ([WXApi registerApp: appid universalLink: universalLink]) {
 | 
					    @try {
 | 
				
			||||||
        self.appId = appid;
 | 
					        self.appId = appid;
 | 
				
			||||||
        resolve(@[[NSNull null]]);
 | 
					        resolve(@([WXApi registerApp: appid universalLink: universalLink]));
 | 
				
			||||||
    } else {
 | 
					    } @catch (NSException *exception) {
 | 
				
			||||||
        reject(@"-10404", INVOKE_FAILED, nil);
 | 
					        reject(@"-10404", [NSString stringWithFormat:@"%@ %@", exception.name, exception.userInfo], nil);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -62,6 +66,17 @@ RCT_EXPORT_METHOD(isWXAppInstalled: (RCTPromiseResolveBlock)resolve rejecter:(RC
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*! @brief 打开微信
 | 
				
			||||||
 | 
					 * @return 成功返回YES,失败返回NO。
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					RCT_EXPORT_METHOD(openWXApp: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
 | 
				
			||||||
 | 
					    if ([WXApi openWXApp]) {
 | 
				
			||||||
 | 
					        resolve(@YES);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        resolve(@NO);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 判断当前微信的版本是否支持OpenApi,支持返回YES,不支持返回NO。
 | 
					// 判断当前微信的版本是否支持OpenApi,支持返回YES,不支持返回NO。
 | 
				
			||||||
RCT_EXPORT_METHOD(isWXAppSupportApi: (RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) {
 | 
					RCT_EXPORT_METHOD(isWXAppSupportApi: (RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) {
 | 
				
			||||||
    if ([WXApi isWXAppSupportApi]) {
 | 
					    if ([WXApi isWXAppSupportApi]) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user