From ec14ccee87214841787fbd48376809179c8ec4f1 Mon Sep 17 00:00:00 2001
From: jaywcjlove <398188662@qq.com>
Date: Sat, 1 Aug 2020 19:44:52 +0800
Subject: [PATCH] feat: Add isWXAppInstalled props.
---
README.md | 1 +
example/App.js | 16 ++++------------
index.d.ts | 7 ++++++-
index.js | 8 +++++++-
ios/RNWechat.h | 2 +-
ios/RNWechat.m | 13 +++++++++++--
6 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index 26c034e..c977ed8 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
+
diff --git a/example/App.js b/example/App.js
index cf07815..24939b0 100644
--- a/example/App.js
+++ b/example/App.js
@@ -1,22 +1,14 @@
-/**
- * Sample React Native App
- *
- * adapted from App.js generated by the following command:
- *
- * react-native init example
- *
- * https://github.com/facebook/react-native
- */
-
import React, { Component } from 'react';
import { Platform, SafeAreaView, StyleSheet, Text, View } from 'react-native';
-import RNWechat from '@uiw/react-native-wechat';
+import Wechat from '@uiw/react-native-wechat';
export default class App extends Component {
state = {
message: '--'
};
- componentDidMount() {
+ async componentDidMount() {
+ const isInstall = await Wechat.isWXAppInstalled();
+ console.log(':isInstall:', isInstall);
// RNWechat.sampleMethod('Testing', 123, (message) => {
// this.setState({
// message
diff --git a/index.d.ts b/index.d.ts
index af62c63..bd5bd5c 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -4,4 +4,9 @@
* @param appid 通过微信开放平台,[获取appid](https://open.weixin.qq.com/)
* @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。
*/
-export function registerApp(appid: string, universalLink: string): void;
\ No newline at end of file
+export function registerApp(appid: string, universalLink: string): void;
+/**
+ * 检查微信是否已被用户安装
+ * 微信已安装返回 `true`,未安装返回 `false`。
+ */
+export function isWXAppInstalled(): Promise;
\ No newline at end of file
diff --git a/index.js b/index.js
index a6345f6..5cfce4c 100644
--- a/index.js
+++ b/index.js
@@ -9,6 +9,12 @@ export default class Wechat {
* @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。
*/
static registerApp(appid, universalLink) {
- return NativeModules.RNAMapGeolocation.registerApp(appid, universalLink);
+ return NativeModules.RNWechat.registerApp(appid, universalLink);
+ }
+ /**
+ * 检查微信是否已被用户安装
+ */
+ static isWXAppInstalled() {
+ return NativeModules.RNWechat.isWXAppInstalled();
}
}
diff --git a/ios/RNWechat.h b/ios/RNWechat.h
index fa87aa1..2c3afe7 100644
--- a/ios/RNWechat.h
+++ b/ios/RNWechat.h
@@ -3,5 +3,5 @@
#import "WXApiObject.h"
@interface RNWechat : NSObject
-
+@property NSString* appId;
@end
diff --git a/ios/RNWechat.m b/ios/RNWechat.m
index 9c13504..60fd292 100644
--- a/ios/RNWechat.m
+++ b/ios/RNWechat.m
@@ -44,12 +44,21 @@ RCT_EXPORT_MODULE()
}
// 注册 appid
-RCT_REMAP_METHOD(registerApp, resolver: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
- if ([WXApi registerApp:@"wxd930ea5d5a258f4f" universalLink:@"wxd930ea5d5a258f4f"]) {
+RCT_REMAP_METHOD(registerApp, :(NSString *)appid :(NSString *)universalLink resolver: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
+ if ([WXApi registerApp: appid universalLink: universalLink]) {
+ self.appId = appid;
resolve(@[[NSNull null]]);
} else {
reject(@"-10404", INVOKE_FAILED, nil);
}
}
+// 检查微信是否已被用户安装, 微信已安装返回YES,未安装返回NO。
+RCT_REMAP_METHOD(isWXAppInstalled, :(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) {
+ if ([WXApi isWXAppInstalled]) {
+ resolve(@YES);
+ } else {
+ resolve(@NO);
+ }
+}
@end