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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//
// ShareViewController.m
// Lighting
//
// Created by mac on 16/5/23.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "ShareViewController.h"
@interface ShareViewController ()
@end
@implementation ShareViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self initSubview];
}
-(void)initSubview
{
self.weiXinFriend=[[UIButton alloc]initWithFrame:CGRectMake(25, 25,60 , 60)];
[self.weiXinFriend setBackgroundImage:[UIImage imageNamed:@"wechat"] forState:UIControlStateNormal];
self.weiXinFriend.tag=101;
[self.weiXinFriend addTarget:self action:@selector(sharePicture:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.weiXinFriend];
UILabel *lable1=[[UILabel alloc]initWithFrame:CGRectMake(25+5, 90, 60, 40)];
lable1.text=@"微信好友";
lable1.font=[UIFont systemFontOfSize:12];
[self.view addSubview:lable1];
self.weiXinFriendCircle=[[UIButton alloc]initWithFrame:CGRectMake(25+25+60, 25,60 , 60)];
[self.weiXinFriendCircle setBackgroundImage:[UIImage imageNamed:@"Friends-Circle"] forState:UIControlStateNormal];
self.weiXinFriendCircle.tag=102;
[self.weiXinFriendCircle addTarget:self action:@selector(sharePicture:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.weiXinFriendCircle];
UILabel *lable2=[[UILabel alloc]initWithFrame:CGRectMake(25+25+60, 90, 60, 40)];
lable2.text=@"微信朋友圈";
lable2.font=[UIFont systemFontOfSize:12];
[self.view addSubview:lable2];
self.sinaMicroBlog=[[UIButton alloc]initWithFrame:CGRectMake(25+25+60+25+60, 25,60 , 60)];
[self.sinaMicroBlog setBackgroundImage:[UIImage imageNamed:@"weibo"] forState:UIControlStateNormal];
self.sinaMicroBlog.tag=103;
[self.sinaMicroBlog addTarget:self action:@selector(sharePicture:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.sinaMicroBlog];
UILabel *lable3=[[UILabel alloc]initWithFrame:CGRectMake(25+25+60+25+60+5, 90, 60, 40)];
lable3.text=@"新浪微博";
lable3.font=[UIFont systemFontOfSize:12];
[self.view addSubview:lable3];
}
#pragma mark -分享
-(void)sharePicture:(UIButton*)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
NSData *imageData = UIImageJPEGRepresentation(self.shareImage, 1.0);
// 0b44439e5504e371015504f73d4f0025,0b44439e5504e371015504feae270028
NSDictionary *parameterDict = [NSDictionary dictionaryWithObjectsAndKeys:self.goodsIDs,@"goodsIds",@"",@"title",@"",@"remark",nil];
//上传图片
[[NetworkRequestClassManager Manager] UploadImageWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/system/shareGoods"] WithRequestType:0 WithImageDatas:imageData WithParameter:parameterDict WithReturnValueBlock:^(id returnValue) {
if ([returnValue[@"code"] isEqualToNumber:@0]) {
NSString *shareWeb = returnValue[@"data"][@"url"];
switch (sender.tag) {
case 101: //微信好友
{//自定义样式
//使用UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite分别代表微信好友、微信朋友圈、微信收藏
[UMSocialData defaultData].extConfig.wechatSessionData.url = shareWeb;
[[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWechatSession] content:ShareTitle image:self.shareImage location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
[self SuccessMBProgressView:@"分享微信好友成功"];
}
}];
}
break;
case 102://微信朋友圈
{
//使用UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite分别代表微信好友、微信朋友圈、微信收藏
[UMSocialData defaultData].extConfig.wechatTimelineData.url = shareWeb;
[[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWechatTimeline] content:ShareTitle image:self.shareImage location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
[self SuccessMBProgressView:@"分享微信朋友圈成功"];
}
}];
}
break;
case 103://新浪微博
{
//自定义分享样式
[UMSocialData defaultData].extConfig.sinaData.shareText = [NSString stringWithFormat:@"%@%@",@"欧普照明",shareWeb];
[[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina] content:ShareTitle image:self.shareImage location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *shareResponse){
if (shareResponse.responseCode == UMSResponseCodeSuccess) {
[self SuccessMBProgressView:@"分享新浪微博成功"];
}
}];
}
break;
default:
break;
}
}else
{
if ([self.delegate respondsToSelector:@selector(CodeNotEqualZero:)]) {
[self.delegate CodeNotEqualZero:returnValue[@"message"]];
}
}
}WithprogressBlock:^(double progress) {
if (progress >= 1) {
if ([self.delegate respondsToSelector:@selector(UploadImageSuccess)]) {
[self.delegate UploadImageSuccess];
}
}else
{
if ([self.delegate respondsToSelector:@selector(UploadImageProgress:)]) {
[self.delegate UploadImageProgress:progress];
}
}
} WithErrorCodeBlock:^(id errorCodeValue) {
} WithFailureBlock:^(NSError *error) {
if ([self.delegate respondsToSelector:@selector(UploadImageFailue)]) {
[self.delegate UploadImageFailue];
}
}];
}
//实现回调方法:
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
//根据`responseCode`得到发送结果,如果分享成功
if(response.responseCode == UMSResponseCodeSuccess)
{
//得到分享到的微博平台名
NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
}
}
- (void)viewDidDisappear:(BOOL)animated;
{
if ([self.delegate respondsToSelector:@selector(resetShareBtn)]) {
[self.delegate resetShareBtn];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end