Commit 2e2b5b3c cgx

模拟Apple授权登录

1 个父辈 8afb9f55
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
D0506B1B2805500E00229278 /* SafeHelperCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0506B1A2805500E00229278 /* SafeHelperCollectionViewCell.m */; }; D0506B1B2805500E00229278 /* SafeHelperCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0506B1A2805500E00229278 /* SafeHelperCollectionViewCell.m */; };
D070509A28071BAF006D72E1 /* DSNetworkTool.m in Sources */ = {isa = PBXBuildFile; fileRef = D070509928071BAF006D72E1 /* DSNetworkTool.m */; }; D070509A28071BAF006D72E1 /* DSNetworkTool.m in Sources */ = {isa = PBXBuildFile; fileRef = D070509928071BAF006D72E1 /* DSNetworkTool.m */; };
D07F9DE927F4683B0036372F /* DKColorTable.txt in Resources */ = {isa = PBXBuildFile; fileRef = D07F9DE827F4683B0036372F /* DKColorTable.txt */; }; D07F9DE927F4683B0036372F /* DKColorTable.txt in Resources */ = {isa = PBXBuildFile; fileRef = D07F9DE827F4683B0036372F /* DKColorTable.txt */; };
D091BBB72808F9DA00487A50 /* BreathTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = D091BBB62808F9DA00487A50 /* BreathTextView.m */; };
D091BBBB2809079600487A50 /* NSString+Extras.m in Sources */ = {isa = PBXBuildFile; fileRef = D091BBBA2809079600487A50 /* NSString+Extras.m */; };
D0930F122801124E006B497A /* BaseNaviController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0930F112801124E006B497A /* BaseNaviController.m */; }; D0930F122801124E006B497A /* BaseNaviController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0930F112801124E006B497A /* BaseNaviController.m */; };
D0930F1A2801874B006B497A /* UIViewController+Swizzling.m in Sources */ = {isa = PBXBuildFile; fileRef = D0930F152801874B006B497A /* UIViewController+Swizzling.m */; }; D0930F1A2801874B006B497A /* UIViewController+Swizzling.m in Sources */ = {isa = PBXBuildFile; fileRef = D0930F152801874B006B497A /* UIViewController+Swizzling.m */; };
D0930F1B2801874B006B497A /* UINavigationController+Pop.m in Sources */ = {isa = PBXBuildFile; fileRef = D0930F182801874B006B497A /* UINavigationController+Pop.m */; }; D0930F1B2801874B006B497A /* UINavigationController+Pop.m in Sources */ = {isa = PBXBuildFile; fileRef = D0930F182801874B006B497A /* UINavigationController+Pop.m */; };
...@@ -127,6 +129,11 @@ ...@@ -127,6 +129,11 @@
D070509928071BAF006D72E1 /* DSNetworkTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DSNetworkTool.m; sourceTree = "<group>"; }; D070509928071BAF006D72E1 /* DSNetworkTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DSNetworkTool.m; sourceTree = "<group>"; };
D07F9D0627F45CB20036372F /* DKNightVersion.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DKNightVersion.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D07F9D0627F45CB20036372F /* DKNightVersion.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DKNightVersion.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D07F9DE827F4683B0036372F /* DKColorTable.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DKColorTable.txt; sourceTree = "<group>"; }; D07F9DE827F4683B0036372F /* DKColorTable.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DKColorTable.txt; sourceTree = "<group>"; };
D091BBB52808F9DA00487A50 /* BreathTextView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BreathTextView.h; sourceTree = "<group>"; };
D091BBB62808F9DA00487A50 /* BreathTextView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BreathTextView.m; sourceTree = "<group>"; };
D091BBB82809024100487A50 /* DreamSleepBeta.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DreamSleepBeta.entitlements; sourceTree = "<group>"; };
D091BBB92809079600487A50 /* NSString+Extras.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+Extras.h"; sourceTree = "<group>"; };
D091BBBA2809079600487A50 /* NSString+Extras.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+Extras.m"; sourceTree = "<group>"; };
D0930F102801124E006B497A /* BaseNaviController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BaseNaviController.h; sourceTree = "<group>"; }; D0930F102801124E006B497A /* BaseNaviController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BaseNaviController.h; sourceTree = "<group>"; };
D0930F112801124E006B497A /* BaseNaviController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BaseNaviController.m; sourceTree = "<group>"; }; D0930F112801124E006B497A /* BaseNaviController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BaseNaviController.m; sourceTree = "<group>"; };
D0930F152801874B006B497A /* UIViewController+Swizzling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Swizzling.m"; sourceTree = "<group>"; }; D0930F152801874B006B497A /* UIViewController+Swizzling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Swizzling.m"; sourceTree = "<group>"; };
...@@ -278,6 +285,8 @@ ...@@ -278,6 +285,8 @@
D0F80906280431100097899F /* UILabel+Extras.m */, D0F80906280431100097899F /* UILabel+Extras.m */,
D0506B0A280503A800229278 /* UIButton+Extras.h */, D0506B0A280503A800229278 /* UIButton+Extras.h */,
D0506B0B280503A800229278 /* UIButton+Extras.m */, D0506B0B280503A800229278 /* UIButton+Extras.m */,
D091BBB92809079600487A50 /* NSString+Extras.h */,
D091BBBA2809079600487A50 /* NSString+Extras.m */,
); );
path = Category; path = Category;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -393,6 +402,7 @@ ...@@ -393,6 +402,7 @@
D0B5ECA327F2D9DE003EDFE3 /* DreamSleep */ = { D0B5ECA327F2D9DE003EDFE3 /* DreamSleep */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
D091BBB82809024100487A50 /* DreamSleepBeta.entitlements */,
D0F808ED2803C83A0097899F /* DreamSleepDebug.entitlements */, D0F808ED2803C83A0097899F /* DreamSleepDebug.entitlements */,
D0E9408127FE961300D57495 /* Vendors */, D0E9408127FE961300D57495 /* Vendors */,
D04567AA27F6D067009F0A82 /* Main */, D04567AA27F6D067009F0A82 /* Main */,
...@@ -490,6 +500,8 @@ ...@@ -490,6 +500,8 @@
D0F808F32803D4E70097899F /* Track.m */, D0F808F32803D4E70097899F /* Track.m */,
D0C09EDE28007E5F00709D4C /* BreatheController.h */, D0C09EDE28007E5F00709D4C /* BreatheController.h */,
D0C09EDF28007E5F00709D4C /* BreatheController.m */, D0C09EDF28007E5F00709D4C /* BreatheController.m */,
D091BBB52808F9DA00487A50 /* BreathTextView.h */,
D091BBB62808F9DA00487A50 /* BreathTextView.m */,
); );
path = BreathingMethod; path = BreathingMethod;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -708,6 +720,7 @@ ...@@ -708,6 +720,7 @@
D0E65FFF2807AC5E006562F2 /* DSProgressHUD.m in Sources */, D0E65FFF2807AC5E006562F2 /* DSProgressHUD.m in Sources */,
D0E660022807B5AE006562F2 /* SafeSleepRequestModel.m in Sources */, D0E660022807B5AE006562F2 /* SafeSleepRequestModel.m in Sources */,
D0E6600828080F97006562F2 /* SystemSetController.m in Sources */, D0E6600828080F97006562F2 /* SystemSetController.m in Sources */,
D091BBB72808F9DA00487A50 /* BreathTextView.m in Sources */,
D04B3DBB27F6F7940022F8DF /* AISleepCoachController.m in Sources */, D04B3DBB27F6F7940022F8DF /* AISleepCoachController.m in Sources */,
D027EE2627FB3DC0004BBA61 /* NetLoadingStateView.m in Sources */, D027EE2627FB3DC0004BBA61 /* NetLoadingStateView.m in Sources */,
D0C09EE028007E5F00709D4C /* BreatheController.m in Sources */, D0C09EE028007E5F00709D4C /* BreatheController.m in Sources */,
...@@ -720,6 +733,7 @@ ...@@ -720,6 +733,7 @@
D0F80907280431100097899F /* UILabel+Extras.m in Sources */, D0F80907280431100097899F /* UILabel+Extras.m in Sources */,
D04B3DAC27F6EEB50022F8DF /* DSTabBarController.m in Sources */, D04B3DAC27F6EEB50022F8DF /* DSTabBarController.m in Sources */,
D0C50B4F27FD832300DC68F0 /* LeadView.m in Sources */, D0C50B4F27FD832300DC68F0 /* LeadView.m in Sources */,
D091BBBB2809079600487A50 /* NSString+Extras.m in Sources */,
D01814EB28002A8200583D4E /* DsMiddleView.m in Sources */, D01814EB28002A8200583D4E /* DsMiddleView.m in Sources */,
D0C50B4227FD39C800DC68F0 /* UIViewController+FullScreenModal.m in Sources */, D0C50B4227FD39C800DC68F0 /* UIViewController+FullScreenModal.m in Sources */,
D027EE2927FB51D0004BBA61 /* DSGifHeader.m in Sources */, D027EE2927FB51D0004BBA61 /* DSGifHeader.m in Sources */,
...@@ -1038,7 +1052,7 @@ ...@@ -1038,7 +1052,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
Bundle_Display_Name = "小梦睡眠-Beta"; Bundle_Display_Name = "小梦睡眠-Beta";
CODE_SIGN_ENTITLEMENTS = DreamSleep/DreamSleep.entitlements; CODE_SIGN_ENTITLEMENTS = DreamSleep/DreamSleepBeta.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution"; CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
<key>com.apple.developer.associated-domains</key> <key>com.apple.developer.associated-domains</key>
<array> <array>
<string>applinks:https://www.cbti.cn/sleep_apple</string> <string>applinks:https://www.cbti.cn/sleep_apple</string>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:https://www.cbti.cn/sleep_apple</string>
</array>
</dict>
</plist>
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
#import "ProfileController.h" #import "ProfileController.h"
#import "SystemSetController.h" #import "SystemSetController.h"
#import <AuthenticationServices/AuthenticationServices.h>
@interface ProfileController () @interface ProfileController () <ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding>
@property (nonatomic, strong) NSArray *tmpDatas; @property (nonatomic, strong) NSArray *tmpDatas;
@end @end
...@@ -19,7 +20,7 @@ ...@@ -19,7 +20,7 @@
self.navigationItem.title = @"我的"; self.navigationItem.title = @"我的";
self.tableView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG); self.tableView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
self.tmpDatas = @[@"注册登录信息", @"意见反馈", @"系统设置", @"邀请好友", @"关于我们", @"前往小程序", @"关注公众号", @"添加客服微信", @"失眠的认知行为疗法"]; self.tmpDatas = @[@"注册登录信息", @"意见反馈", @"系统设置", @"邀请好友", @"关于我们", @"前往小程序", @"关注公众号", @"添加客服微信", @"失眠的认知行为疗法", @"模拟Apple登录"];
} }
#pragma mark - 导航栏日间、黑夜模式 #pragma mark - 导航栏日间、黑夜模式
...@@ -51,9 +52,126 @@ ...@@ -51,9 +52,126 @@
[self.navigationController pushViewController:sysVC animated:YES]; [self.navigationController pushViewController:sysVC animated:YES];
} }
break; break;
case 9: // 模拟苹果登录
{
[self handleAuthrization];
}
break;
default: default:
break; break;
} }
} }
#pragma mark - 点击苹果登录授权按钮
- (void)handleAuthrization {
if (@available(iOS 13.0, *)) {
// 基于用户的Apple ID授权用户,生成用户授权请求的一种机制
ASAuthorizationAppleIDProvider *appleIDProvider = [ASAuthorizationAppleIDProvider new];
// 创建新的AppleID 授权请求
ASAuthorizationAppleIDRequest *request = appleIDProvider.createRequest;
// 在用户授权期间请求的联系信息
request.requestedScopes = @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail];
// 由ASAuthorizationAppleIDProvider创建的授权请求 管理授权请求的控制器
ASAuthorizationController *controller = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[request]];
// 设置授权控制器通知授权请求的成功与失败的代理
controller.delegate = self;
// 设置提供 展示上下文的代理,在这个上下文中 系统可以展示授权界面给用户
controller.presentationContextProvider = self;
// 在控制器初始化期间启动授权流
[controller performRequests];
}
}
#pragma mark - ASAuthorizationControllerDelegate
#pragma mark - 授权成功地回调
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization API_AVAILABLE(ios(13.0)) {
NSLog(@"%s", __FUNCTION__);
NSLog(@"%@", controller);
NSLog(@"%@", authorization);
NSLog(@"authorization.credential:%@", authorization.credential);
if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) {
ASAuthorizationAppleIDCredential *credential = authorization.credential;
NSLog(@"credential = %@", credential);
NSString *state = credential.state;
NSString *userID = credential.user;
NSPersonNameComponents *fullName = credential.fullName;
NSString *email = credential.email;
NSString *authorizationCode = [[NSString alloc] initWithData:credential.authorizationCode encoding:NSUTF8StringEncoding]; // 验证 token
NSString *identityToken = [[NSString alloc] initWithData:credential.identityToken encoding:NSUTF8StringEncoding]; // 用户 token
ASUserDetectionStatus realUserStatus = credential.realUserStatus;
NSArray *authorizedScopes = credential.authorizedScopes;
NSLog(@"ios登陆成功 state: %@\nuserID: %@\nfullName: %@\nemail: %@\nauthorizationCode: %@\nidentityToken: %@\nrealUserStatus: %@\nauthorizedScopes: %@",
state,
userID,
fullName,
email,
authorizationCode,
identityToken,
@(realUserStatus),
authorizedScopes);
// // 用户登录使用ASAuthorizationAppleIDCredential
// ASAuthorizationAppleIDCredential *appleIDCredential = authorization.credential;
// // 用户ID: user,苹果用户唯一标识,该值在同一个开发者账号下的所有 App 下是一样的。
// NSString *user = appleIDCredential.user;
// // 使用钥匙串的方式保存用户的唯一信息
// NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
//
// // 验证数据: identityToken , authorizationCode ,用于服务端验证授权请求的合法性。
// NSString *authorizationCode = [[NSString alloc] initWithData:appleIDCredential.authorizationCode encoding:NSUTF8StringEncoding];
// NSString *identityToken = [[NSString alloc] initWithData:appleIDCredential.identityToken encoding:NSUTF8StringEncoding];
//
// NSLog(@"user:%@, bundleId:%@, authorizationCode:%@, identityToken:%@", user, bundleId, authorizationCode, identityToken);
// 通过钥匙串保存用户授权信息
// [SAMKeychain setPassword:user forService:bundleId account:ShareCurrentIdentifier];
} else if ([authorization.credential isKindOfClass:[ASPasswordCredential class]]) {
// 用户登录使用现有的密码凭证
ASPasswordCredential *passwordCredential = authorization.credential;
// 密码凭证对象的用户标识 用户的唯一标识
NSString *user = passwordCredential.user;
// 密码凭证对象的密码
NSString *password = passwordCredential.password;
NSLog(@"user:%@, password:%@", user, password);
} else {
NSLog(@"授权信息均不符");
}
}
#pragma mark - 授权失败的回调
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error API_AVAILABLE(ios(13.0)) {
NSLog(@"%s", __FUNCTION__);
NSLog(@"错误信息:%@", error);
NSString *errorMsg = nil;
switch (error.code) {
case ASAuthorizationErrorCanceled:
errorMsg = @"用户取消了授权请求";
break;
case ASAuthorizationErrorFailed:
errorMsg = @"授权请求失败";
break;
case ASAuthorizationErrorInvalidResponse:
errorMsg = @"授权请求响应无效";
break;
case ASAuthorizationErrorNotHandled:
errorMsg = @"未能处理授权请求";
break;
case ASAuthorizationErrorUnknown:
errorMsg = @"授权请求失败未知原因";
break;
}
NSLog(@"controller requests:%@, errorMsg:%@", controller.authorizationRequests, errorMsg);
}
#pragma mark - ASAuthorizationControllerPresentationContextProviding
#pragma mark - 告诉代理应该在哪个window 展示内容给用户
- (ASPresentationAnchor)presentationAnchorForAuthorizationController:(ASAuthorizationController *)controller API_AVAILABLE(ios(13.0)){
NSLog(@"调用展示window方法:%s", __FUNCTION__);
// 返回window
return self.view.window;
}
@end @end
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!