iOS-功能总结(1)--ShareSDK登录与分享
最近项⽬中要集成分享与三⽅登录功能,我之前⽤的都是友盟分享,队友把分享写完了,⽤的是shareSDK,看了⼀下代码与⽹上的简书,照着来了⼀次,感觉还不错,有需求的同学可以直接学习。本⽂下⾯的步骤是转载,先著名链接
www.jianshu/p/4be1105d4cc6
⼀、完成对好友、朋友圈、收藏、新浪微博、QQ好友、QQ空间、短信、邮件等主流平台的图⽚、⽂字、URL分享等功能 在博主的项⽬中我增加了对本地视频⽂件的分享功能(仅好友)、另有QQ空间的视频分享功能(ShareSDK For iOS v3.4.0(2016-08-03)
⼆、第三⽅QQ//微博的登录
三、开发环境:Xcode7.3.1 ShareSDK版本为ShareSDK For iOS v3.3.1
PS:(ShareSDK For iOS v3.4.0(2016-08-03)⽀持了QQ空间的视频分享功能
四、对于MOB官⽅⽂档中所介绍的⽅法 写在我们VC的分享按钮触发事件中 显得太杂乱、没有灵活性,在这⾥博主对ShareSDK的分享功能做了⼀次封装,可以让我们在VC中调⽤的时候显得更加的灵活且好管理
1、关于ShareSDK的准备⼯作,在MOB的官⽅⽂档中有详细的说明在这⾥我就不多说了。
2、步⼊正题之代码
3、在APPDelegate中调⽤
Paste_Image.png
具体步骤
1、新建ShareSDKTool类继承与NSObject
长在树上的蔬菜2、代码部分
(1)导⼊ShareSDK类库中这些类名
Paste_Image.png
(2)注册ShareSDK
(3)分享图⽚、⽂本、URL等⾄好友、朋友圈、收藏、新浪微博、QQ好友、QQ空间、短信、邮件等平台#pragma mark - 注册ShareSDK +(void )registerShare { //registerApp 初始化SDK 并且初始化第三⽅平台 [ShareSDK registerApp:K_ShareSDK_AppKey activePlatforms:@[ @(SSDKPlatformTypeSinaWeibo), @(SSDKPlatformTypeMail), @(SSDKPlatformTypeSMS), @(SSDKPlatformTypeWechat), @(SSDKPlatformTypeQQ), ] onImport:^(SSDKPlatformType platformType) { switch (platformType) { case SSDKPlatformTypeWechat:{ [ShareSDKConnector connectWeChat:[WXApi class ]]; break ; } case SSDKPlatformTypeSinaWeibo: [ShareSDKConnector connectWeibo:[WeiboSDK class ]]; break ; case SSDKPlatformTypeQQ: [ShareSDKConnector connectQQ:[QQApiInterface class ] tencentOAuthClass:[TencentOAuth class ]]; break ; default : break ; } } onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) { sw
itch (platformType) { case SSDKPlatformTypeWechat: [appInfo SSDKSetupWeChatByAppId:K_WX_AppID appSecret:K_WX_AppSecret]; break ; case SSDKPlatformTypeSinaWeibo: [appInfo SSDKSetupSinaWeiboByAppKey:K_Sina_AppKey appSecret:K_Sina_AppSecret redirectUri:K_Share_Url authType:SSDKAuthTypeBoth]; break ; case SSDKPlatformTypeQQ: [appInfo SSDKSetupQQByAppId:K_QQ_AppId appKey:K_QQ_AppKey authType:SSDKAuthTypeBoth]; break ; default : break ; } } ];
}
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#pragma mark- 分享+(void )shareContentWithShareContentType:(SSDKContentType)shareContentType contentTitle:(NSString *)contentTitle contentDescription:(NSString *)contentDescription contentImage:(id )contentImage contentURL:(NSString *)contentURL showInView:(UIView *)showInView 1
2
3
4
5
6
7
failure:(void (^)(NSString *failureInfo))failure OtherResponseStatus:(void (^)(SSDKResponseState state))otherResponseStatus{ //1. 创建分享参数 NSMutableDictionary *shareParams = [NSMutableDictionary dictionary]; [shareParams SSDKEnableUseClientShare]; [shareParams SSDKSetupShareParamsByText:contentDescription images:contentImage url:[NSURL URLWithString:contentURL] title:contentTitle type:shareContentType]; //2. 分享,显⽰分享view SSUIShareActionSheetController *sheet =[ShareSDK showShareActionSheet:showInView items:nil shareParams:shareParams onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntit switch (state) { case SSDKResponseStateBegin: { break ; } case SSDKResponseStateSuccess: { success(); break ; } case SSDKResponseStateFail: { if (platformType == SSDKPlatformTypeSMS && [error code] == 201) {
failure(@"失败原因可能是:1、短信应⽤没有设置帐号;2、设备不⽀持短信应⽤;3、短信应⽤在iOS 7以上才能发送带附件的短 break ; } else if (platformType == SSDKPlatformTypeMail && [error code] == 201) { failure(@"失败原因可能是:1、邮件应⽤没有设置帐号;2、设备不⽀持邮件应⽤。"); break ; } else { failure([NSString stringWithFormat:@"%@",error]); break ; } break ; } case SSDKResponseStateCancel: { otherResponseStatus(SSDKResponseStateCancel); break ; } default : break ;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
(4)⽂件分享(本地相册中的视频)分享–>仅好友可分享(设置title、sourceFileExtension、sourceFileData,以及thumbImage等参数) if (state != SSDKResponseStateBegin) { failure([NSString stringWithFormat:@"%@",error]); } }]; [sheet.directSharePlatforms addObject:@(SSDKPlatformTypeSinaWeibo)]; [sheet.directSharePlatforms addObject:@(SSDKPlatformTypeMail)]; [sheet.directSharePlatforms addObject:@(SSDKPlatformTypeSMS)];
}
74
75
76
77
78
79
80
81
82
83#pragma mark 分享⽂件代码(仅⽀持好友)+ (void )shareVideoContentParamsByText:(NSString *)text title:(NSString *)title url:(NSURL *)url thumbImage:(id )thumbImage image:(id )image musicFileURL:(NSURL *)musicFileURL extInfo:(NSString *)extInfo fileData:(id )fileData emoticonData:(id )emoticonData sourceFileExtension:(NSString *)fileExtension sourceFileData:(id )sourceFileData type:(SSDKContentType)type forPlatformSubType:(SSDKPlatformType)platformSubType showInView:(UIView *)showInView
success:(void (^)())success failure:(void (^)(NSString *failureInfo))failure OtherResponseStatus:(void (^)(SSDKResponseState state))otherResponseStatus{ //1. 创建分享参数 NSMutableDictionary *shareParams = [NSMutableDictionary dictionary]; [shareParams SSDKEnableUseClientShare]; [shareParams SSDKSetupWeChatParamsByText:text title:title url:url thumbImage:thumbImage image:image musicFileURL:musicFileURL extInfo:extInfo NSArray *items = @[@(SSDKPlatformSubTypeWechatSession)]; //2. 分享->显⽰分享view SSUIShareActionSheetController *sheet = [ShareSDK showShareActionSheet:showInView items:items shareParams:shareParams onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, switch (state) { case SSDKResponseStateBegin: { break ; } case SSDKResponseStateSuccess: { success(); break ; } case SSDKResponseStateFail: { if (platformType == SSDKPlatformTypeSMS && [error code] == 201)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
比较好的号id号37
38
39
40
41
42
43
44
45
46
47
48
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论