InviteController.m
4.8 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// InviteController.m
// DreamSleep
//
// Created by peter on 2022/4/18.
//
#import "InviteController.h"
#import <YYWebImage/YYWebImage.h>
#import <UMShare/UMShare.h>
@interface InviteController ()
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) YYAnimatedImageView *animatedView;
@end
@implementation InviteController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"邀请好友";
self.view.backgroundColor = DSWhite;
[self.view addSubview:self.scrollView];
UIButton *shareBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
[shareBtn setImage:[UIImage imageNamed:@"shareIcon"] forState:UIControlStateNormal];
[shareBtn addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:shareBtn];
}
- (void)shareAction {
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"模拟分享" message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"微信好友" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self shareTextToPlatformType:UMSocialPlatformType_WechatSession];
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"朋友圈" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self shareTextToPlatformType:UMSocialPlatformType_WechatTimeLine];
}];
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"QQ好友" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self shareTextToPlatformType:UMSocialPlatformType_QQ];
}];
UIAlertAction *action4 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
[alertVC addAction:action1];
[alertVC addAction:action2];
[alertVC addAction:action3];
[alertVC addAction:action4];
[self presentViewController:alertVC animated:YES completion:nil];
}
#pragma mark - 友盟分享
- (void)shareTextToPlatformType:(UMSocialPlatformType)platformType {
// 创建分享消息对象
UMSocialMessageObject*messageObject = [UMSocialMessageObject messageObject];
// 创建图片内容对象
UMShareImageObject*shareObject =[[UMShareImageObject alloc] init];
// 如果有缩略图,则设置缩略图
shareObject.thumbImage = [UIImage imageNamed:@"icon"];
UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForAuxiliaryExecutable:@"invite_friend.webp"]];
[shareObject setShareImage:img];
// 分享消息对象设置分享内容对象
messageObject.shareObject = shareObject;
// 调用分享接口
[[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data,NSError*error) {
if (error) {
if (error.code == 2008) {
[DSProgressHUD showToast:(platformType == UMSocialPlatformType_QQ) ? @"您的设备未安装QQ" : @"您的设备未安装微信"];
}
UMSocialLogInfo(@"************Share fail with error %@*********", error);
} else {
if ([data isKindOfClass:[UMSocialShareResponse class]]) {
UMSocialShareResponse *resp = data;
// 分享结果消息
UMSocialLogInfo(@"response message is %@", resp.message);
// 第三方原始返回的数据
UMSocialLogInfo(@"response originalResponse data is %@", resp.originalResponse);
} else {
UMSocialLogInfo(@"response data is %@", data);
}
}
}];
}
- (UIScrollView *)scrollView {
if (!_scrollView) {
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTopHeight(0))];
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.bounces = NO;
_scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[_scrollView addSubview:self.animatedView];
}
return _scrollView;
}
- (YYAnimatedImageView *)animatedView {
if (!_animatedView) {
UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForAuxiliaryExecutable:@"invite_friend.webp"]];
_animatedView = [[YYAnimatedImageView alloc] initWithFrame:self.scrollView.bounds];
CGFloat h = kScreenWidth * img.size.height / img.size.width;
_animatedView.height = h;
_scrollView.contentSize = CGSizeMake(kScreenWidth, h);
_animatedView.image = img;
}
return _animatedView;
}
@end