index.ios.js
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
"use strict";
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity
} = React;
var WeChat = require('./react-native-wechat.js');
class Example extends React.Component {
constructor(props) {
super(props);
this.state = {
apiVersion: 'waiting...',
wxAppInstallUrl: 'waiting...',
isWXAppSupportApi: 'waiting...',
isWXAppInstalled: 'waiting...',
};
}
async componentDidMount() {
try {
await WeChat.registerApp('1234567');
this.setState({
apiVersion: await WeChat.getApiVersion(),
wxAppInstallUrl: await WeChat.getWXAppInstallUrl(),
isWXAppSupportApi: await WeChat.isWXAppSupportApi(),
isWXAppInstalled: await WeChat.isWXAppInstalled()
});
console.log(this.state);
} catch (e) {
console.error(e);
}
console.log(WeChat);
// console.log('getApiVersion', typeof WeChat.getApiVersion);
// console.log('getWXAppInstallUrl', typeof WeChat.getWXAppInstallUrl);
// console.log('sendRequest', typeof WeChat.sendRequest);
// console.log('registerApp', typeof WeChat.registerApp);
// console.log('sendErrorCommonResponse', typeof WeChat.sendErrorCommonResponse);
// console.log('sendErrorUserCancelResponse', typeof WeChat.sendErrorUserCancelResponse);
// console.log('sendAuthRequest', typeof WeChat.sendAuthRequest);
// console.log('getWXAppInstallUrl', typeof WeChat.getWXAppInstallUrl);
// console.log('openWXApp', typeof WeChat.openWXApp);
// console.log('registerAppWithDescription', typeof WeChat.registerAppWithDescription);
// console.log('isWXAppSupportApi', typeof WeChat.isWXAppSupportApi);
// console.log('isWXAppInstalled', typeof WeChat.isWXAppInstalled);
}
render() {
return (
<View style={styles.container}>
<Text>api版本:{this.state.apiVersion}</Text>
<Text>微信注册url:{this.state.wxAppInstallUrl}</Text>
<Text>是否支持api:{String(this.state.isWXAppSupportApi)}</Text>
<Text>是否安装微信:{String(this.state.isWXAppInstalled)}</Text>
<TouchableOpacity onPress={this._openWXApp}>
<Text>打开微信</Text>
</TouchableOpacity>
</View>
);
}
async _openWXApp() {
await WeChat.openWXApp();
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('Example', () => Example);