Skip to content

Commit ec14cce

Browse files
committed
feat: Add isWXAppInstalled props.
1 parent b8d93e9 commit ec14cce

File tree

6 files changed

+30
-17
lines changed

6 files changed

+30
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<br />
12
<p align="center">
23
<a href="https://uiwjs.github.io/react-native-wechat/">
34
<img src="https://user-images.githubusercontent.com/1680273/89100258-46cf6a00-d428-11ea-96dc-8b07a0ee277c.png" height="100" />

example/App.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
/**
2-
* Sample React Native App
3-
*
4-
* adapted from App.js generated by the following command:
5-
*
6-
* react-native init example
7-
*
8-
* https://github.com/facebook/react-native
9-
*/
10-
111
import React, { Component } from 'react';
122
import { Platform, SafeAreaView, StyleSheet, Text, View } from 'react-native';
13-
import RNWechat from '@uiw/react-native-wechat';
3+
import Wechat from '@uiw/react-native-wechat';
144

155
export default class App extends Component {
166
state = {
177
message: '--'
188
};
19-
componentDidMount() {
9+
async componentDidMount() {
10+
const isInstall = await Wechat.isWXAppInstalled();
11+
console.log(':isInstall:', isInstall);
2012
// RNWechat.sampleMethod('Testing', 123, (message) => {
2113
// this.setState({
2214
// message

index.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
* @param appid 通过微信开放平台,[获取appid](https://open.weixin.qq.com/)
55
* @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。
66
*/
7-
export function registerApp(appid: string, universalLink: string): void;
7+
export function registerApp(appid: string, universalLink: string): void;
8+
/**
9+
* 检查微信是否已被用户安装
10+
* 微信已安装返回 `true`,未安装返回 `false`。
11+
*/
12+
export function isWXAppInstalled(): Promise<Boolean>;

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ export default class Wechat {
99
* @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。
1010
*/
1111
static registerApp(appid, universalLink) {
12-
return NativeModules.RNAMapGeolocation.registerApp(appid, universalLink);
12+
return NativeModules.RNWechat.registerApp(appid, universalLink);
13+
}
14+
/**
15+
* 检查微信是否已被用户安装
16+
*/
17+
static isWXAppInstalled() {
18+
return NativeModules.RNWechat.isWXAppInstalled();
1319
}
1420
}

ios/RNWechat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#import "WXApiObject.h"
44

55
@interface RNWechat : NSObject <RCTBridgeModule, WXApiDelegate>
6-
6+
@property NSString* appId;
77
@end

ios/RNWechat.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,21 @@ + (BOOL)requiresMainQueueSetup {
4444
}
4545

4646
// 注册 appid
47-
RCT_REMAP_METHOD(registerApp, resolver: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
48-
if ([WXApi registerApp:@"wxd930ea5d5a258f4f" universalLink:@"wxd930ea5d5a258f4f"]) {
47+
RCT_REMAP_METHOD(registerApp, :(NSString *)appid :(NSString *)universalLink resolver: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
48+
if ([WXApi registerApp: appid universalLink: universalLink]) {
49+
self.appId = appid;
4950
resolve(@[[NSNull null]]);
5051
} else {
5152
reject(@"-10404", INVOKE_FAILED, nil);
5253
}
5354
}
5455

56+
// 检查微信是否已被用户安装, 微信已安装返回YES,未安装返回NO。
57+
RCT_REMAP_METHOD(isWXAppInstalled, :(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) {
58+
if ([WXApi isWXAppInstalled]) {
59+
resolve(@YES);
60+
} else {
61+
resolve(@NO);
62+
}
63+
}
5564
@end

0 commit comments

Comments
 (0)