TemplateShareManager.m
3.59 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
//
// TemplateShareManager.m
// CNLiveScioLive
//
// Created by CNLive-zxw on 2018/10/20.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "TemplateShareManager.h"
@implementation TemplateShareManager
static TemplateShareManager *shareManager = nil;
+ (TemplateShareManager *)manager{
@synchronized(self){
if (shareManager == nil) {
shareManager = [[TemplateShareManager alloc] init];
}
}
return shareManager;
}
#pragma mark 注册ShareSDK分享以及配置信息
- (void)shareConfig {
[ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
//QQ
[platformsRegister setupQQWithAppId:@"1105424006" appkey:@"EneqtYjiKSswk05g"];
//微信
[platformsRegister setupWeChatWithAppId:@"wx1eb184b8425c2503" appSecret:@"4d250e1ef3b7f5f1bc3579237fd4ee62"];
//新浪
[platformsRegister setupSinaWeiboWithAppkey:@"604714517" appSecret:@"542573f3d166742a230634d5c2576157" redirectUrl:@"https://api.weibo.com/oauth2/default.html"];
}];
}
- (void)shareImage:(NSString *)image title:(NSString *)title text:(NSString *)text url:(NSString *)url controller:(UIViewController *)controller {
NSArray *imageArray = nil;
if (!image||[image isEqualToString:@""]) {
imageArray = @[[UIImage imageNamed:@"cnlive_zhouxin_icon"]];
} else {
imageArray = @[image];
}
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
[shareParams SSDKSetupShareParamsByText:text images:imageArray url:[NSURL URLWithString:url?url:@"http://app.scio.gov.cn/gxbShare.html"] title:title type:SSDKContentTypeWebPage];
NSArray *items = @[
@(SSDKPlatformSubTypeWechatSession),
@(SSDKPlatformSubTypeWechatTimeline),
@(SSDKPlatformTypeQQ),
@(SSDKPlatformTypeSinaWeibo)
];
[ShareSDK showShareActionSheet:nil customItems:items shareParams:shareParams sheetConfiguration:nil onStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
switch (state) {
case SSDKResponseStateSuccess:
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:CustomStr(@"ShareSuccess") message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:CustomStr(@"Sure") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了确定,进入确定的事件");
}];
[alert addAction:action1];
[controller presentViewController:alert animated:YES completion:nil];
break;
}
case SSDKResponseStateFail:
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:CustomStr(@"ShareFailure") message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:CustomStr(@"Sure") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了确定,进入确定的事件");
}];
[alert addAction:action1];
[controller presentViewController:alert animated:YES completion:nil];
break;
}
default:
break;
}
}];
}
@end