Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
GMShareSDK
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMShareSDK
Commits
25d4872f
Commit
25d4872f
authored
5 years ago
by
井庆林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加苹果登录
parent
18b8bdd4
master
ajp/dev
jql/appleLogin
jz/master
lwq
lwq7.37.0
lwq_7.40.1_shareSdk
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
2 merge requests
!1
Master
,
!3
添加苹果登录
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
1 deletion
+74
-1
GMThirdPartyDefine.h
GMShareSDK/Classes/ShareSDK/GMThirdPartyDefine.h
+2
-0
GMThirdPartyLoginHelper.h
GMShareSDK/Classes/ShareSDK/GMThirdPartyLoginHelper.h
+2
-0
GMThirdPartyLoginHelper.m
GMShareSDK/Classes/ShareSDK/GMThirdPartyLoginHelper.m
+25
-0
GMThirdPartyOauthManager.h
GMShareSDK/Classes/ShareSDK/GMThirdPartyOauthManager.h
+1
-0
GMThirdPartyOauthManager.m
GMShareSDK/Classes/ShareSDK/GMThirdPartyOauthManager.m
+44
-1
No files found.
GMShareSDK/Classes/ShareSDK/GMThirdPartyDefine.h
View file @
25d4872f
...
@@ -39,6 +39,7 @@ typedef NS_ENUM(NSInteger, GMSharePlatform) {
...
@@ -39,6 +39,7 @@ typedef NS_ENUM(NSInteger, GMSharePlatform) {
GMSharePlatformWechat
=
100
,
/**< 微信平台*/
GMSharePlatformWechat
=
100
,
/**< 微信平台*/
GMSharePlatformQQ
=
101
,
/**< QQ平台*/
GMSharePlatformQQ
=
101
,
/**< QQ平台*/
GMSharePlatformDouyin
=
102
,
/**< 抖音*/
GMSharePlatformDouyin
=
102
,
/**< 抖音*/
GMSharePlatformApple
=
103
/**苹果登录*/
};
};
...
@@ -103,6 +104,7 @@ typedef NS_ENUM(NSUInteger, GMShareContentType){
...
@@ -103,6 +104,7 @@ typedef NS_ENUM(NSUInteger, GMShareContentType){
#define kQQLogin @"kQQLogin"
#define kQQLogin @"kQQLogin"
#define kSinaLogin @"kSinaLogin"
#define kSinaLogin @"kSinaLogin"
#define kAppleLogin @"kAppleLogin"
#define kWechatLogin @"kWechatLogin"
#define kWechatLogin @"kWechatLogin"
#define kWechatPaySuccess @"kWechatPaySuccess"
#define kWechatPaySuccess @"kWechatPaySuccess"
#define kWechatPayFail @"kWechatPayFail"
#define kWechatPayFail @"kWechatPayFail"
...
...
This diff is collapsed.
Click to expand it.
GMShareSDK/Classes/ShareSDK/GMThirdPartyLoginHelper.h
View file @
25d4872f
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
@property
(
nonatomic
,
copy
)
NSString
*
city
;
@property
(
nonatomic
,
copy
)
NSString
*
city
;
@property
(
nonatomic
,
assign
)
GMSharePlatform
platformType
;
@property
(
nonatomic
,
assign
)
GMSharePlatform
platformType
;
@property
(
nonatomic
,
copy
)
NSString
*
thirdDetail
;
@property
(
nonatomic
,
copy
)
NSString
*
thirdDetail
;
@property
(
nonatomic
,
copy
)
NSString
*
email
;
@property
(
nonatomic
,
copy
)
NSString
*
authorizationCode
;
@end
@end
...
...
This diff is collapsed.
Click to expand it.
GMShareSDK/Classes/ShareSDK/GMThirdPartyLoginHelper.m
View file @
25d4872f
...
@@ -53,6 +53,31 @@
...
@@ -53,6 +53,31 @@
userHandler
(
state
,
note
.
object
);
userHandler
(
state
,
note
.
object
);
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
observer
];
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
observer
];
}];
}];
}
else
if
(
platform
==
GMSharePlatformApple
)
{
if
(
@available
(
iOS
13
.
0
,
*
))
{
// 基于用户的Apple ID授权用户,生成用户授权请求的一种机制
ASAuthorizationAppleIDProvider
*
appleIDProvider
=
[[
ASAuthorizationAppleIDProvider
alloc
]
init
];
// 创建新的AppleID 授权请求
ASAuthorizationAppleIDRequest
*
appleIDRequest
=
[
appleIDProvider
createRequest
];
// 在用户授权期间请求的联系信息
appleIDRequest
.
requestedScopes
=
@[
ASAuthorizationScopeFullName
,
ASAuthorizationScopeEmail
];
// 由ASAuthorizationAppleIDProvider创建的授权请求 管理授权请求的控制器
ASAuthorizationController
*
authorizationController
=
[[
ASAuthorizationController
alloc
]
initWithAuthorizationRequests
:@[
appleIDRequest
]];
// 设置授权控制器通知授权请求的成功与失败的代理
authorizationController
.
delegate
=
[
GMThirdPartyOauthManager
shareInstance
];
// 设置提供 展示上下文的代理,在这个上下文中 系统可以展示授权界面给用户
authorizationController
.
presentationContextProvider
=
[
GMThirdPartyOauthManager
shareInstance
];
// 在控制器初始化期间启动授权流
[
authorizationController
performRequests
];
__block
id
observer
=
[[
NSNotificationCenter
defaultCenter
]
addObserverForName
:
kAppleLogin
object
:
nil
queue
:
[
NSOperationQueue
mainQueue
]
usingBlock
:^
(
NSNotification
*
_Nonnull
note
)
{
GMShareResponseState
state
=
(
GMShareResponseState
)[
note
.
userInfo
[
@"state"
]
integerValue
];
userHandler
(
state
,
note
.
object
);
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
observer
];
}];
}
else
{
userHandler
(
GMShareResponseStateFail
,
nil
);
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
GMShareSDK/Classes/ShareSDK/GMThirdPartyOauthManager.h
View file @
25d4872f
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
#import <WechatOpenSDK/WXApi.h>
#import <WechatOpenSDK/WXApi.h>
#import <Weibo_SDK/WeiboSDK.h>
#import <Weibo_SDK/WeiboSDK.h>
#import <DouyinOpenSDK/DouyinOpenSDKApi.h>
#import <DouyinOpenSDK/DouyinOpenSDKApi.h>
#import <AuthenticationServices/AuthenticationServices.h>
//这里是接受三方授权的回调
//这里是接受三方授权的回调
@interface
GMThirdPartyOauthManager
:
NSObject
<
TencentSessionDelegate
,
QQApiInterfaceDelegate
,
WXApiDelegate
,
WeiboSDKDelegate
,
DouyinOpenSDKApiDelegate
>
@interface
GMThirdPartyOauthManager
:
NSObject
<
TencentSessionDelegate
,
QQApiInterfaceDelegate
,
WXApiDelegate
,
WeiboSDKDelegate
,
DouyinOpenSDKApiDelegate
>
...
...
This diff is collapsed.
Click to expand it.
GMShareSDK/Classes/ShareSDK/GMThirdPartyOauthManager.m
View file @
25d4872f
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
@interface
GMThirdPartyOauthManager
()
<
WBHttpRequestDelegate
,
DouyinOpenSDKLogDelegate
>
@interface
GMThirdPartyOauthManager
()
<
WBHttpRequestDelegate
,
DouyinOpenSDKLogDelegate
,
ASAuthorizationControllerDelegate
,
ASAuthorizationControllerPresentationContextProviding
>
@end
@end
@implementation
GMThirdPartyOauthManager
@implementation
GMThirdPartyOauthManager
...
@@ -46,6 +46,8 @@
...
@@ -46,6 +46,8 @@
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
kSinaLogin
object
:
nil
userInfo
:
@{
@"state"
:
@
(
GMShareResponseStateBack
)}];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
kSinaLogin
object
:
nil
userInfo
:
@{
@"state"
:
@
(
GMShareResponseStateBack
)}];
}
else
if
(
_user
.
platformType
==
GMSharePlatformWechat
){
}
else
if
(
_user
.
platformType
==
GMSharePlatformWechat
){
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
kWechatLogin
object
:
nil
userInfo
:
@{
@"state"
:
@
(
GMShareResponseStateBack
)}];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
kWechatLogin
object
:
nil
userInfo
:
@{
@"state"
:
@
(
GMShareResponseStateBack
)}];
}
else
if
(
_user
.
platformType
==
GMSharePlatformApple
){
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
kAppleLogin
object
:
nil
userInfo
:
@{
@"state"
:
@
(
GMShareResponseStateBack
)}];
}
}
}
}
}
}
...
@@ -290,6 +292,47 @@
...
@@ -290,6 +292,47 @@
}
}
}
}
#pragma mark - Apple delegate
//@optional 授权成功地回调
-
(
void
)
authorizationController
:
(
ASAuthorizationController
*
)
controller
didCompleteWithAuthorization
:
(
ASAuthorization
*
)
authorization
API_AVAILABLE
(
ios
(
13
.
0
)){
if
(
@available
(
iOS
13
.
0
,
*
))
{
if
([
authorization
.
credential
isKindOfClass
:[
ASAuthorizationAppleIDCredential
class
]])
{
// 用户登录使用ASAuthorizationAppleIDCredential
ASAuthorizationAppleIDCredential
*
appleIDCredential
=
(
ASAuthorizationAppleIDCredential
*
)
authorization
.
credential
;
NSString
*
user
=
appleIDCredential
.
user
;
// 使用过授权的,可能获取不到以下三个参数
NSString
*
fimilyName
=
appleIDCredential
.
fullName
.
familyName
?:
@""
;
NSString
*
givenName
=
appleIDCredential
.
fullName
.
givenName
?:
@""
;
NSData
*
identityToken
=
appleIDCredential
.
identityToken
;
NSData
*
authorizationCode
=
appleIDCredential
.
authorizationCode
;
_user
.
uid
=
appleIDCredential
.
user
;
_user
.
nickname
=
[
fimilyName
stringByAppendingString
:
givenName
];
_user
.
email
=
appleIDCredential
.
email
;
_user
.
thirdDetail
=
[[
NSString
alloc
]
initWithData
:
identityToken
encoding
:
NSUTF8StringEncoding
];
_user
.
authorizationCode
=
[[
NSString
alloc
]
initWithData
:
authorizationCode
encoding
:
NSUTF8StringEncoding
];
_user
.
platformType
=
GMSharePlatformApple
;
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
kAppleLogin
object
:
_user
userInfo
:
@{
@"state"
:
@
(
GMShareResponseStateSuccess
)}];
}
else
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
kAppleLogin
object
:
nil
userInfo
:
@{
@"state"
:
@
(
GMShareResponseStateFail
)}];
}
}
else
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
kAppleLogin
object
:
nil
userInfo
:
@{
@"state"
:
@
(
GMShareResponseStateFail
)}];
}
}
// 授权失败的回调
-
(
void
)
authorizationController
:
(
ASAuthorizationController
*
)
controller
didCompleteWithError
:
(
NSError
*
)
error
API_AVAILABLE
(
ios
(
13
.
0
)){
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
kAppleLogin
object
:
nil
userInfo
:
@{
@"state"
:
@
(
error
.
code
==
ASAuthorizationErrorCanceled
?
GMShareResponseStateCancel
:
GMShareResponseStateFail
)}];
}
// 告诉代理应该在哪个window 展示内容给用户
-
(
ASPresentationAnchor
)
presentationAnchorForAuthorizationController
:
(
ASAuthorizationController
*
)
controller
API_AVAILABLE
(
ios
(
13
.
0
)){
// 返回window
return
[
UIApplication
sharedApplication
].
windows
.
lastObject
;
}
-
(
void
)
onLog
:
(
NSString
*
)
log
{
-
(
void
)
onLog
:
(
NSString
*
)
log
{
NSLog
(
@"%@"
,
log
);
NSLog
(
@"%@"
,
log
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment