-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.ios.js
executable file
·171 lines (131 loc) · 4.06 KB
/
index.ios.js
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
* http://www.mob.com kengsir
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View, TouchableHighlight
} from 'react-native';
// ------------------------------------------------------------------------------
ShareSDK = require('./ShareSDK')
// -----------------------------------------------------------------------------
activePlatforms = [
ShareSDK.platformType.SinaWeibo,
ShareSDK.platformType.TencentWeibo,
ShareSDK.platformType.Wechat,
ShareSDK.platformType.QQ,
]
// 设置各个平台初始化
// platforms
totalPlatforms = {
[ShareSDK.platformType.SinaWeibo] : {
app_key:'568898243',
app_secret:'38a4f8204cc784f81f9f0daaf31e02e3',
redirect_uri:'http://www.sharesdk.cn',
authType: ShareSDK.authType.Both
},
[ShareSDK.platformType.TencentWeibo] : {
app_key: '801307650',
app_secret: 'ae36f4ee3946e1cbb98d6965b0b2ff5c',
redirect_uri: 'http://www.sharesdk.cn',
authType: ShareSDK.authType.Both
},
[ShareSDK.platformType.Wechat] : {
app_id: 'wx4868b35061f87885',
app_secret: '64020361b8ec4c99936c0e3999a9f249',
authType: ShareSDK.authType.Both
},
[ShareSDK.platformType.QQ] : {
app_id: '100371282',
app_secret: 'aed9b0303e3ed1e27bae87c33761161d',
authType: ShareSDK.authType.Both
}
// Facebook
// Twitter
// Google plus
// TODO 平台 app_key,app_id 参数信息表请戳:-》
}
// 初始化方法
ShareSDK.registerApp('iosv1001',activePlatforms,totalPlatforms);
// 构造分享参数
shareParams = {
text: '分享内容',
images: '',
url: 'http://www.mob.com',
title: '分享标题',
type: ShareSDK.contentType.Auto
}
// TODO 每个平台分享不同的内容
// DEMO中的分享按钮
class CustomButton extends React.Component{
render(){
return(
<TouchableHighlight style={styles.button} underlayColor="#a5a5a5" onPress={this.props.onPress}>
<Text style={styles.buttonText}>{this.props.text}</Text>
</TouchableHighlight>);
}
}
class RNShareSDK extends Component {
// 在此方法中设置回调
componentWillMount() {
ShareSDK.callBack();
}
render() {
return (
<View>
<CustomButton onPress={()=>{
// 分享,传入需要分享的平台,已经构建好的分享参数
ShareSDK.share(ShareSDK.platformType.SinaWeibo,shareParams)
}
} text="无UI分享"/>
<CustomButton onPress={()=>{
// 弹出actionSheet进行分享
ShareSDK.showShareActionSheet(activePlatforms,shareParams)
}
} text="弹出ActionSheet分享"/>
<CustomButton onPress={()=>{
// 弹出编辑框进行分享
ShareSDK.showShareEditor(ShareSDK.platformType.SinaWeibo,shareParam)
}
} text="弹出编辑框分享"/>
<CustomButton onPress={()=>{
// 平台授权
ShareSDK.authorize(ShareSDK.platformType.SinaWeibo)
}
} text="授权"/>
<CustomButton onPress={()=>{
// 平台授权
if(ShareSDK.hasAuthorized(ShareSDK.platformType.SinaWeibo)){
console.log("已经授权");}
else{
console.log("还未授权");
}
}
} text="检查平台是否已经授权"/>
<CustomButton onPress={()=>{
ShareSDK.cancelAuthorize(ShareSDK.platformType.SinaWeibo);
alert("平台取消授权成功")}
} text="取消授权"/>
</View>
);
}
}
const styles = StyleSheet.create({
button : {
margin:5,
backgroundColor:'green',
padding:15,
borderBottomWidth:StyleSheet.hairlineWidth,
borderBottomColor:'#cdcdcd'
},
buttonText: {
margin:5,
flex:1
},
});
AppRegistry.registerComponent('RNShareSDK', () => RNShareSDK);