TemplateShareManager.m
4.98 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// TemplateShareManager.m
// CNLiveScioLive
//
// Created by CNLive-zxw on 2018/10/20.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "TemplateShareManager.h"
#import "TemplateShareButton.h"
@implementation TemplateShareManager
static TemplateShareManager *shareManaager = nil;
+ (TemplateShareManager *)shareSingleton{
@synchronized(self){
if (shareManaager == nil) {
shareManaager = [[TemplateShareManager alloc] init];
}
}
return shareManaager;
}
#pragma mark 注册友盟分享以及配置信息
- (void)shareConfig
{
[ShareSDK registerApp:@"134f952a9e004" activePlatforms:@[@(SSDKPlatformTypeSinaWeibo),
@(SSDKPlatformSubTypeWechatSession),
@(SSDKPlatformSubTypeWechatTimeline),
@(SSDKPlatformTypeQQ)]
onImport:^(SSDKPlatformType platformType)
{
switch (platformType)
{
case SSDKPlatformTypeWechat:
[ShareSDKConnector connectWeChat:[WXApi class]];
break;
case SSDKPlatformTypeQQ:
[ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
break;
case SSDKPlatformTypeSinaWeibo:
[ShareSDKConnector connectWeibo:[WeiboSDK class]];
break;
default:
break;
}
}
onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
{
switch (platformType)
{
case SSDKPlatformTypeSinaWeibo:
//设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权
[appInfo SSDKSetupSinaWeiboByAppKey:@"604714517"
appSecret:@"542573f3d166742a230634d5c2576157"
redirectUri:@"https://api.weibo.com/oauth2/default.html"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeWechat:
[appInfo SSDKSetupWeChatByAppId:@"wx1eb184b8425c2503"
appSecret:@"4d250e1ef3b7f5f1bc3579237fd4ee62"];
break;
case SSDKPlatformTypeQQ:
[appInfo SSDKSetupQQByAppId:@"1105424006"
appKey:@"EneqtYjiKSswk05g"
authType:SSDKAuthTypeBoth];
break;
default:
break;
}
}];
}
- (void)shareType:(TemplateShareButtonType)type shareImage:(id)shareImage shareTitle:(NSString *)shareTitle shareText:(NSString *)shareText shareUrl:(NSString *)shareUrl{
//1、创建分享参数
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
[shareParams SSDKSetupShareParamsByText:shareText images:shareImage url:[NSURL URLWithString:shareUrl] title:shareTitle type:SSDKContentTypeAuto];
//2、分享
if (type == TemplateShareButtonTypeWeiXin){
//微信
[self startSharePlatform:SSDKPlatformTypeWechat parameters:shareParams];
}
else if (type == TemplateShareButtonTypePengYouQuan) {
//朋友圈
[self startSharePlatform:SSDKPlatformSubTypeWechatTimeline parameters:shareParams];
}
else if (type == TemplateShareButtonTypeXLWeiBo){
//新浪微博
[self startSharePlatform:SSDKPlatformTypeSinaWeibo parameters:shareParams];
}
else if (type == TemplateShareButtonTypeQQ){
//qq
[self startSharePlatform:SSDKPlatformTypeQQ parameters:shareParams];
}
else if (type == TemplateShareButtonTypeQQZone){
//qq空间
[self startSharePlatform:SSDKPlatformSubTypeQZone parameters:shareParams];
}
}
- (void)startSharePlatform:(SSDKPlatformType)platform parameters:(NSMutableDictionary *)parameters{
[ShareSDK share:platform parameters:parameters onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
switch (state) {
case SSDKResponseStateSuccess:
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:CustomStr(@"ShareSuccess") message:nil delegate:nil cancelButtonTitle:CustomStr(@"Sure") otherButtonTitles:nil];
[alertView show];
break;
}
case SSDKResponseStateFail:
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:CustomStr(@"ShareFailure") message:[NSString stringWithFormat:@"%@",error] delegate:nil cancelButtonTitle:CustomStr(@"Sure") otherButtonTitles:nil];
[alertView show];
break;
}
default:
break;
}
}];
}
@end