feat: Add isWXAppInstalled props.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
<br />
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://uiwjs.github.io/react-native-wechat/">
|
<a href="https://uiwjs.github.io/react-native-wechat/">
|
||||||
<img src="https://user-images.githubusercontent.com/1680273/89100258-46cf6a00-d428-11ea-96dc-8b07a0ee277c.png" height="100" />
|
<img src="https://user-images.githubusercontent.com/1680273/89100258-46cf6a00-d428-11ea-96dc-8b07a0ee277c.png" height="100" />
|
||||||
|
@@ -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 React, { Component } from 'react';
|
||||||
import { Platform, SafeAreaView, StyleSheet, Text, View } from 'react-native';
|
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 {
|
export default class App extends Component {
|
||||||
state = {
|
state = {
|
||||||
message: '--'
|
message: '--'
|
||||||
};
|
};
|
||||||
componentDidMount() {
|
async componentDidMount() {
|
||||||
|
const isInstall = await Wechat.isWXAppInstalled();
|
||||||
|
console.log(':isInstall:', isInstall);
|
||||||
// RNWechat.sampleMethod('Testing', 123, (message) => {
|
// RNWechat.sampleMethod('Testing', 123, (message) => {
|
||||||
// this.setState({
|
// this.setState({
|
||||||
// message
|
// message
|
||||||
|
7
index.d.ts
vendored
7
index.d.ts
vendored
@@ -4,4 +4,9 @@
|
|||||||
* @param appid 通过微信开放平台,[获取appid](https://open.weixin.qq.com/)
|
* @param appid 通过微信开放平台,[获取appid](https://open.weixin.qq.com/)
|
||||||
* @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。
|
* @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。
|
||||||
*/
|
*/
|
||||||
export function registerApp(appid: string, universalLink: string): void;
|
export function registerApp(appid: string, universalLink: string): void;
|
||||||
|
/**
|
||||||
|
* 检查微信是否已被用户安装
|
||||||
|
* 微信已安装返回 `true`,未安装返回 `false`。
|
||||||
|
*/
|
||||||
|
export function isWXAppInstalled(): Promise<Boolean>;
|
8
index.js
8
index.js
@@ -9,6 +9,12 @@ export default class Wechat {
|
|||||||
* @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。
|
* @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。
|
||||||
*/
|
*/
|
||||||
static registerApp(appid, universalLink) {
|
static registerApp(appid, universalLink) {
|
||||||
return NativeModules.RNAMapGeolocation.registerApp(appid, universalLink);
|
return NativeModules.RNWechat.registerApp(appid, universalLink);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 检查微信是否已被用户安装
|
||||||
|
*/
|
||||||
|
static isWXAppInstalled() {
|
||||||
|
return NativeModules.RNWechat.isWXAppInstalled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,5 +3,5 @@
|
|||||||
#import "WXApiObject.h"
|
#import "WXApiObject.h"
|
||||||
|
|
||||||
@interface RNWechat : NSObject <RCTBridgeModule, WXApiDelegate>
|
@interface RNWechat : NSObject <RCTBridgeModule, WXApiDelegate>
|
||||||
|
@property NSString* appId;
|
||||||
@end
|
@end
|
||||||
|
@@ -44,12 +44,21 @@ RCT_EXPORT_MODULE()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 注册 appid
|
// 注册 appid
|
||||||
RCT_REMAP_METHOD(registerApp, resolver: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
RCT_REMAP_METHOD(registerApp, :(NSString *)appid :(NSString *)universalLink resolver: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
if ([WXApi registerApp:@"wxd930ea5d5a258f4f" universalLink:@"wxd930ea5d5a258f4f"]) {
|
if ([WXApi registerApp: appid universalLink: universalLink]) {
|
||||||
|
self.appId = appid;
|
||||||
resolve(@[[NSNull null]]);
|
resolve(@[[NSNull null]]);
|
||||||
} else {
|
} else {
|
||||||
reject(@"-10404", INVOKE_FAILED, nil);
|
reject(@"-10404", INVOKE_FAILED, nil);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查微信是否已被用户安装, 微信已安装返回YES,未安装返回NO。
|
||||||
|
RCT_REMAP_METHOD(isWXAppInstalled, :(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) {
|
||||||
|
if ([WXApi isWXAppInstalled]) {
|
||||||
|
resolve(@YES);
|
||||||
|
} else {
|
||||||
|
resolve(@NO);
|
||||||
|
}
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
Reference in New Issue
Block a user