feat(Android): Add isWXAppInstalled/isWXAppSupportApi props.
This commit is contained in:
@@ -54,6 +54,15 @@ https://uiwjs.github.io/react-native-wechat/apple-app-site-association
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>iOS: -canOpenURL: failed for URL: "weixin://".</summary>
|
||||||
|
|
||||||
|
> ```
|
||||||
|
> -canOpenURL: failed for URL: "weixin://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
|
||||||
|
> ```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>iOS: RCTBridge required dispatch_sync to load RCTDevLoadingView.</summary>
|
<summary>iOS: RCTBridge required dispatch_sync to load RCTDevLoadingView.</summary>
|
||||||
|
|
||||||
|
@@ -29,7 +29,7 @@ public class RNWechatModule extends ReactContextBaseJavaModule {
|
|||||||
public void registerApp(String appid, Promise promise) {
|
public void registerApp(String appid, Promise promise) {
|
||||||
try {
|
try {
|
||||||
this.appId = appid;
|
this.appId = appid;
|
||||||
api = WXAPIFactory.createWXAPI(reactContext.getApplicationContext(), appid, true);
|
api = WXAPIFactory.createWXAPI(reactContext.getApplicationContext(), null, false);
|
||||||
promise.resolve(api.registerApp(appid));
|
promise.resolve(api.registerApp(appid));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
promise.reject("-1", e.getMessage());
|
promise.reject("-1", e.getMessage());
|
||||||
@@ -47,5 +47,29 @@ public class RNWechatModule extends ReactContextBaseJavaModule {
|
|||||||
promise.reject("-1", e.getMessage());
|
promise.reject("-1", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ReactMethod
|
||||||
|
public void isWXAppInstalled(Promise promise) {
|
||||||
|
try {
|
||||||
|
if (api == null) {
|
||||||
|
throw new Exception(NOT_REGISTERED);
|
||||||
|
}
|
||||||
|
promise.resolve(api.isWXAppInstalled());
|
||||||
|
} catch (Exception e) {
|
||||||
|
promise.reject("-1", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void isWXAppSupportApi(Promise promise) {
|
||||||
|
try {
|
||||||
|
if (api == null) {
|
||||||
|
throw new Exception(NOT_REGISTERED);
|
||||||
|
}
|
||||||
|
int wxSdkVersion = api.getWXAppSupportAPI();
|
||||||
|
promise.resolve(wxSdkVersion);
|
||||||
|
} catch (Exception e) {
|
||||||
|
promise.reject("-1", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -9,12 +9,19 @@ export default class App extends Component {
|
|||||||
version: null,
|
version: null,
|
||||||
};
|
};
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
|
try {
|
||||||
|
const reg = await Wechat.registerApp('wxd930ea5d5a258f4f');
|
||||||
|
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)
|
||||||
this.setState({
|
this.setState({
|
||||||
isInstall, isWXAppSupportApi, version
|
isInstall, isWXAppSupportApi, version
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log('error>', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
const { isInstall, isWXAppSupportApi, version } = this.state;
|
const { isInstall, isWXAppSupportApi, version } = this.state;
|
||||||
@@ -29,7 +36,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> - v{version}</Text>
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
|
Reference in New Issue
Block a user