Skip to content

Commit 36863ad

Browse files
author
Jasper
committed
重构登录接口·
1 parent be722d4 commit 36863ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1736
-1034
lines changed

CYUtilProject/.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// CYShare+Login.h
3+
// CYUtilProject
4+
//
5+
// Created by xn011644 on 17/11/2017.
6+
// Copyright © 2017 Charry. All rights reserved.
7+
//
8+
9+
#import "CYShare.h"
10+
11+
#if CY_WECHAT_ENABLED
12+
#import "CYWechat+Login.h"
13+
#endif
14+
15+
#if CY_QQ_ENABLED
16+
#import "CYQQ+Login.h"
17+
#endif
18+
19+
#if CY_SINA_WEIBO_ENABLED
20+
#import "CYSinaWeibo+Login.h"
21+
#endif
22+
23+
#if CY_FACEBOOK_ENABLED
24+
#import "CYFacebook+Login.h"
25+
#endif
26+
27+
@interface CYShare (Login)
28+
29+
#if CY_WECHAT_ENABLED
30+
31+
+ (BOOL)loginByWechat:(NSArray<NSString *>*)permissions callback:(CYLoginCallback)callback;
32+
+ (BOOL)loginByWechat:(NSArray<NSString *> *)permissions fromViewController:(UIViewController *)viewController callback:(CYLoginCallback)callback;
33+
34+
#endif
35+
36+
37+
@end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// CYShare+Login.m
3+
// CYUtilProject
4+
//
5+
// Created by xn011644 on 17/11/2017.
6+
// Copyright © 2017 Charry. All rights reserved.
7+
//
8+
9+
#import "CYShare+Login.h"
10+
11+
@implementation CYShare (Login)
12+
13+
#if CY_WECHAT_ENABLED
14+
15+
+ (BOOL)loginByWechat:(NSArray<NSString *>*)permissions callback:(CYLoginCallback)callback {
16+
return [[CYWechat sharedInstance] loginWithPermissions:permissions callback:callback];
17+
}
18+
19+
+ (BOOL)loginByWechat:(NSArray<NSString *> *)permissions fromViewController:(UIViewController *)viewController callback:(CYLoginCallback)callback {
20+
return [[CYWechat sharedInstance] loginWithPermissions:permissions fromViewController:viewController callback:callback];
21+
}
22+
23+
#endif
24+
25+
@end

CYUtilProject/CYShareSDK/CYShare.h

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
#import <Foundation/Foundation.h>
1010
#import "CYShareCtrlFlag.h"
1111

12-
#if CY_SHARE_WECHAT_ENABLED
12+
#if CY_WECHAT_ENABLED
1313
#import "CYWechat.h"
1414
#endif
1515

16-
#if CY_SHARE_QQ_ENABLED
16+
#if CY_QQ_ENABLED
1717
#import "CYQQ.h"
1818
#endif
1919

20-
#if CY_SHARE_SINA_WEIBO_ENABLED
20+
#if CY_SINA_WEIBO_ENABLED
2121
#import "CYSinaWeibo.h"
2222
#endif
2323

@@ -29,11 +29,15 @@
2929
#import "CYSMS.h"
3030
#endif
3131

32+
#if CY_FACEBOOK_ENABLED
33+
#import "CYFacebook.h"
34+
#endif
35+
3236
#import "CYShareModel.h"
3337

3438
@interface CYShare : NSObject
3539

36-
#if CY_SHARE_WECHAT_ENABLED
40+
#if CY_WECHAT_ENABLED
3741
/**
3842
* 微信注册,appId和appKey为微信开放平台注册之后,微信分配给第三方的appId和appKey
3943
*/
@@ -43,19 +47,15 @@
4347
/**
4448
* 微信分享,由开发者指定分享给好友或者分享到朋友圈
4549
*/
46-
+ (void)shareToWechat:(CYShareModel *)model
47-
scene:(CYWechatScene)scene
48-
callback:(CYShareCallback)callback;
50+
+ (void)shareToWechat:(CYShareModel *)model scene:(CYWechatScene)scene callback:(CYShareCallback)callback;
4951

5052
/**
5153
* 微信分享,弹出ActionSheet,由用户选择分享给好友或者分享到朋友圈
5254
*/
53-
+ (void)shareToWechat:(CYShareModel *)model
54-
presentActionSheetFrom:(UIViewController *)viewController
55-
callback:(CYShareCallback)callback;
55+
+ (void)shareToWechat:(CYShareModel *)model fromViewController:(UIViewController *)viewController callback:(CYShareCallback)callback;
5656
#endif
5757

58-
#if CY_SHARE_QQ_ENABLED
58+
#if CY_QQ_ENABLED
5959
/**
6060
* qq注册,appId和appKey为qq互联平台注册之后,qq分配给第三方的appId和appKey
6161
*/
@@ -65,19 +65,15 @@ presentActionSheetFrom:(UIViewController *)viewController
6565
/**
6666
* qq分享,由开发者指定分享给好友或者分享到qq空间
6767
*/
68-
+ (void)shareToQQ:(CYShareModel *)model
69-
ctrlFlag:(CYQQAPICtrlFlag)flag
70-
callback:(CYShareCallback)callback;
68+
+ (void)shareToQQ:(CYShareModel *)model ctrlFlag:(CYQQAPICtrlFlag)flag callback:(CYShareCallback)callback;
7169

7270
/**
7371
* qq分享,弹出ActionSheet,由用户选择分享给好友或者分享到qq空间
7472
*/
75-
+ (void)shareToQQ:(CYShareModel *)model
76-
presentActionSheetFrom:(UIViewController *)viewController
77-
callback:(CYShareCallback)callback;
73+
+ (void)shareToQQ:(CYShareModel *)model fromViewController:(UIViewController *)viewController callback:(CYShareCallback)callback;
7874
#endif
7975

80-
#if CY_SHARE_SINA_WEIBO_ENABLED
76+
#if CY_SINA_WEIBO_ENABLED
8177
/**
8278
* 新浪微博注册,appKey为微博开放平台注册之后,微博分配给第三方的AppKey
8379
*/
@@ -100,9 +96,7 @@ presentActionSheetFrom:(UIViewController *)viewController
10096
包含文字时,请设置model.content属性
10197
10298
*/
103-
+ (void)shareByAppleActivity:(CYShareModel *)model
104-
presentFrom:(UIViewController *)viewController
105-
callback:(CYShareCallback)callback;
99+
+ (void)shareByAppleActivity:(CYShareModel *)model fromViewController:(UIViewController *)viewController callback:(CYShareCallback)callback;
106100

107101
#endif
108102

@@ -114,16 +108,22 @@ presentActionSheetFrom:(UIViewController *)viewController
114108
目前暂不支持图片分享
115109
116110
*/
117-
+ (void)shareBySMS:(CYShareModel *)model
118-
to:(NSArray *)mobiles
119-
presentFrom:(UIViewController *)viewController
120-
callback:(CYShareCallback)callback;
111+
+ (void)shareBySMS:(CYShareModel *)model to:(NSArray *)mobiles fromViewController:(UIViewController *)viewController callback:(CYShareCallback)callback;
121112

122113
#endif
123114

124-
/**
125-
* 需要在AppDelegate的- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 方法中调用此方法,来处理结果
126-
*/
127-
+ (BOOL)handleOpenURL:(NSURL *)URL;
115+
#if CY_FACEBOOK_ENABLED
116+
117+
+ (void)shareToFacebook:(CYShareModel *)model fromViewController:(UIViewController *)viewController callback:(CYShareCallback)callback;
118+
119+
#endif
120+
121+
#pragma mark - handle open url
122+
// 以下几个方法需要在AppDelegate对应的方法中进行调用,并且必须实现这些方法
123+
+ (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
124+
125+
+ (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;
126+
127+
+ (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
128128

129129
@end

CYUtilProject/CYShareSDK/CYShare.m

Lines changed: 75 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ @interface CYShare ()
1414

1515
@implementation CYShare
1616

17-
#if CY_SHARE_WECHAT_ENABLED
17+
#if CY_WECHAT_ENABLED
1818
+ (void)registerWechatAppId:(NSString *)appId {
1919
[[CYWechat sharedInstance] registerAppId:appId];
2020
}
@@ -23,26 +23,20 @@ + (void)registerWechatAppKey:(NSString *)appKey {
2323
[[CYWechat sharedInstance] registerAppKey:appKey];
2424
}
2525

26-
+ (void)shareToWechat:(CYShareModel *)model
27-
scene:(CYWechatScene)scene
28-
callback:(CYShareCallback)callback {
26+
+ (void)shareToWechat:(CYShareModel *)model scene:(CYWechatScene)scene callback:(CYShareCallback)callback {
2927

3028
[[CYWechat sharedInstance] share:model
3129
to:scene
3230
callback:callback];
3331
}
3432

35-
+ (void)shareToWechat:(CYShareModel *)model
36-
presentActionSheetFrom:(UIViewController *)viewController
37-
callback:(CYShareCallback)callback {
33+
+ (void)shareToWechat:(CYShareModel *)model fromViewController:(UIViewController *)viewController callback:(CYShareCallback)callback {
3834

39-
[[CYWechat sharedInstance] share:model
40-
presentActionSheetFrom:viewController
41-
callback:callback];
35+
[[CYWechat sharedInstance] share:model fromViewController:viewController callback:callback];
4236
}
4337
#endif
4438

45-
#if CY_SHARE_QQ_ENABLED
39+
#if CY_QQ_ENABLED
4640
+ (void)registerQQAppId:(NSString *)appId {
4741
[[CYQQ sharedInstance] registerAppId:appId];
4842
}
@@ -51,25 +45,17 @@ + (void)registerQQAppKey:(NSString *)appKey {
5145
[[CYQQ sharedInstance] registerAppKey:appKey];
5246
}
5347

54-
+ (void)shareToQQ:(CYShareModel *)model
55-
ctrlFlag:(CYQQAPICtrlFlag)flag
56-
callback:(CYShareCallback)callback {
57-
[[CYQQ sharedInstance] share:model
58-
to:flag
59-
callback:callback];
48+
+ (void)shareToQQ:(CYShareModel *)model ctrlFlag:(CYQQAPICtrlFlag)flag callback:(CYShareCallback)callback {
49+
[[CYQQ sharedInstance] share:model to:flag callback:callback];
6050
}
6151

62-
+ (void)shareToQQ:(CYShareModel *)model
63-
presentActionSheetFrom:(UIViewController *)viewController
64-
callback:(CYShareCallback)callback {
52+
+ (void)shareToQQ:(CYShareModel *)model fromViewController:(UIViewController *)viewController callback:(CYShareCallback)callback {
6553

66-
[[CYQQ sharedInstance] share:model
67-
presentActionSheetFrom:viewController
68-
callback:callback];
54+
[[CYQQ sharedInstance] share:model fromViewController:viewController callback:callback];
6955
}
7056
#endif
7157

72-
#if CY_SHARE_SINA_WEIBO_ENABLED
58+
#if CY_SINA_WEIBO_ENABLED
7359
+ (void)registerWeiboAppKey:(NSString *)appKey {
7460
[[CYSinaWeibo sharedInstance] registerAppKey:appKey];
7561
}
@@ -83,40 +69,84 @@ + (void)shareToWeibo:(CYShareModel *)model
8369

8470
#if CY_SHARE_APPLE_ACTIVITY_ENABLED
8571

86-
+ (void)shareByAppleActivity:(CYShareModel *)model
87-
presentFrom:(UIViewController *)viewController
88-
callback:(CYShareCallback)callback {
89-
[[CYAppleActivity sharedInstance] share:model
90-
presentFrom:viewController
91-
callback:callback];
72+
+ (void)shareByAppleActivity:(CYShareModel *)model fromViewController:(UIViewController *)viewController callback:(CYShareCallback)callback {
73+
[[CYAppleActivity sharedInstance] share:model fromViewController:viewController callback:callback];
9274
}
9375

9476
#endif
9577

9678
#if CY_SHARE_SMS_ENABLED
9779

98-
+ (void)shareBySMS:(CYShareModel *)model
99-
to:(NSArray *)mobiles
100-
presentFrom:(UIViewController *)viewController
101-
callback:(CYShareCallback)callback {
102-
[[CYSMS sharedInstance] share:model
103-
toUsers:mobiles
104-
presentFrom:viewController
105-
callback:callback];
80+
+ (void)shareBySMS:(CYShareModel *)model to:(NSArray *)mobiles fromViewController:(UIViewController *)viewController callback:(CYShareCallback)callback {
81+
[[CYSMS sharedInstance] share:model toMobiles:mobiles fromViewController:viewController callback:callback];
82+
}
83+
84+
#endif
85+
86+
#if CY_FACEBOOK_ENABLED
87+
88+
+ (void)shareToFacebook:(CYShareModel *)model fromViewController:(UIViewController *)viewController callback:(CYShareCallback)callback {
89+
[[CYFacebook sharedInstance] share:model fromViewController:viewController callback:callback];
90+
}
91+
92+
#endif
93+
94+
#pragma mark - handle open url
95+
// 以下几个方法需要在AppDelegate对应的方法中进行调用,并且必须实现这些方法
96+
+ (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
97+
BOOL result = NO;
98+
#if CY_WECHAT_ENABLED
99+
result = [[CYWechat sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
100+
#endif
101+
#if CY_QQ_ENABLED
102+
result = (result || [[CYQQ sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]);
103+
#endif
104+
#if CY_SINA_WEIBO_ENABLED
105+
result = (result || [[CYSinaWeibo sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]);
106+
#endif
107+
#if CY_FACEBOOK_ENABLED
108+
result = (result || [[CYFacebook sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]);
109+
#endif
110+
return result;
106111
}
107112

113+
+ (BOOL)application:(UIApplication *)application
114+
openURL:(NSURL *)url
115+
sourceApplication:(NSString *)sourceApplication
116+
annotation:(id)annotation {
117+
118+
BOOL result = NO;
119+
#if CY_WECHAT_ENABLED
120+
result = [[CYWechat sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
121+
#endif
122+
#if CY_QQ_ENABLED
123+
result = (result || [[CYQQ sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]);
108124
#endif
125+
#if CY_SINA_WEIBO_ENABLED
126+
result = (result || [[CYSinaWeibo sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]);
127+
#endif
128+
#if CY_FACEBOOK_ENABLED
129+
result = (result || [[CYFacebook sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]);
130+
#endif
131+
return result;
132+
}
133+
134+
+ (BOOL)application:(UIApplication *)application
135+
openURL:(NSURL *)url
136+
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
109137

110-
+ (BOOL)handleOpenURL:(NSURL *)URL {
111138
BOOL result = NO;
112-
#if CY_SHARE_WECHAT_ENABLED
113-
result = [[CYWechat sharedInstance] handleOpenURL:URL];
139+
#if CY_WECHAT_ENABLED
140+
result = [[CYWechat sharedInstance] application:application openURL:url options:options];
141+
#endif
142+
#if CY_QQ_ENABLED
143+
result = (result || [[CYQQ sharedInstance] application:application openURL:url options:options]);
114144
#endif
115-
#if CY_SHARE_QQ_ENABLED
116-
result = (result || [[CYQQ sharedInstance] handleOpenURL:URL]);
145+
#if CY_SINA_WEIBO_ENABLED
146+
result = (result || [[CYSinaWeibo sharedInstance] application:application openURL:url options:options]);
117147
#endif
118-
#if CY_SHARE_SINA_WEIBO_ENABLED
119-
result = (result || [[CYSinaWeibo sharedInstance] handleOpenURL:URL]);
148+
#if CY_FACEBOOK_ENABLED
149+
result = (result || [[CYFacebook sharedInstance] application:application openURL:url options:options]);
120150
#endif
121151
return result;
122152
}

0 commit comments

Comments
 (0)