439 lines
17 KiB
Objective-C
439 lines
17 KiB
Objective-C
//
|
|
// LoginAppleView.m
|
|
// ProductApp
|
|
//
|
|
// Created by 工作 on 2025/3/27.
|
|
//
|
|
|
|
#import "LoginAppleView.h"
|
|
#import <YYText/YYText.h>
|
|
#import "PublicNetWorkManager.h"
|
|
#import "WkWebviewViewController.h"
|
|
|
|
#import<AuthenticationServices/AuthenticationServices.h>
|
|
#import "TongYiXieYiAlterView.h"
|
|
|
|
#import "AppDelegate.h"
|
|
#import "LoginViewController.h"
|
|
|
|
@interface LoginAppleView ()<ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding>
|
|
///
|
|
@property (nonatomic , strong) UIView *viewother;
|
|
///
|
|
@property (nonatomic , strong) UIButton *btxy;
|
|
@end
|
|
|
|
@implementation LoginAppleView
|
|
|
|
-(id)initWithFrame:(CGRect)frame
|
|
{
|
|
if(self = [super initWithFrame:frame])
|
|
{
|
|
UIImageView *imgvlog = [[UIImageView alloc] init];
|
|
[imgvlog setImage:[UIImage imageNamed:@"log_log"]];
|
|
[self addSubview:imgvlog];
|
|
[imgvlog mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.height.offset(80);
|
|
make.centerX.equalTo(self);
|
|
make.top.offset(NavHeight+20);
|
|
}];
|
|
|
|
UILabel *lbname = [[UILabel alloc] init];
|
|
[lbname setText:@"快存视频"];
|
|
[lbname setTextColor:RGBACOLOR(255, 255, 255, 0.9)];
|
|
[lbname setTextAlignment:NSTextAlignmentLeft];
|
|
[lbname setFont:[UIFont systemFontOfSize:20]];
|
|
[self addSubview:lbname];
|
|
[lbname mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self);
|
|
make.top.equalTo(imgvlog.mas_bottom).offset(12);
|
|
}];
|
|
|
|
UILabel *lbinfo = [[UILabel alloc] init];
|
|
[lbinfo setText:@"为了更好地为您提供服务,请先完成微信授权"];
|
|
[lbinfo setTextColor:RGBCOLOR(153, 153, 153)];
|
|
[lbinfo setTextAlignment:NSTextAlignmentLeft];
|
|
[lbinfo setFont:[UIFont systemFontOfSize:14]];
|
|
[self addSubview:lbinfo];
|
|
[lbinfo mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self);
|
|
make.top.equalTo(lbname.mas_bottom).offset(58);
|
|
}];
|
|
|
|
|
|
|
|
UIView *viewdl = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH-74, 50)];
|
|
[viewdl setBackgroundColor:[UIColor whiteColor]];
|
|
[self addSubview:viewdl];
|
|
[viewdl mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.offset(37);
|
|
make.right.equalTo(self).offset(-37);
|
|
make.top.equalTo(lbinfo.mas_bottom).offset(20);
|
|
make.height.offset(50);
|
|
}];
|
|
[viewdl.layer setMasksToBounds:YES];
|
|
[viewdl.layer setCornerRadius:25];
|
|
[Tools changedView:viewdl colors:@[(id)RGBCOLOR(246, 44, 108).CGColor,(id)RGBCOLOR(252, 79, 84).CGColor] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
|
|
|
|
UIButton *btdenglu = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH-74, 50)];
|
|
[btdenglu setTitle:@"Apple一键登录" forState:UIControlStateNormal];
|
|
[btdenglu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
[btdenglu.titleLabel setFont:[UIFont systemFontOfSize:16]];
|
|
[btdenglu.layer setMasksToBounds:YES];
|
|
[btdenglu.layer setCornerRadius:25];
|
|
[btdenglu setBackgroundColor:[UIColor clearColor]];
|
|
[btdenglu setImage:[Tools imageWithImageName:[UIImage imageNamed:@"login_apple_bai"] imageColor:[UIColor whiteColor]] forState:UIControlStateNormal];
|
|
[self addSubview:btdenglu];
|
|
[btdenglu mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(viewdl);
|
|
}];
|
|
[btdenglu addTarget:self action:@selector(dengluAction) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
|
|
UIView *viewxy = [[UIView alloc] init];
|
|
[self addSubview:viewxy];
|
|
[viewxy mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self);
|
|
make.top.equalTo(btdenglu.mas_bottom).offset(10);
|
|
make.height.offset(30);
|
|
}];
|
|
UIButton *btxy = [[UIButton alloc] init];
|
|
[btxy setImage:[UIImage imageNamed:@"login_selectN"] forState:UIControlStateNormal];
|
|
[btxy setImage:[UIImage imageNamed:@"login_selectY"] forState:UIControlStateSelected];
|
|
[viewxy addSubview:btxy];
|
|
[btxy mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.top.offset(0);
|
|
make.width.offset(30);
|
|
make.height.offset(30);
|
|
}];
|
|
[btxy addTarget:self action:@selector(xieyiAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
_btxy = btxy;
|
|
|
|
YYLabel *lbxy = [[YYLabel alloc] init];
|
|
[lbxy setText:@"我已同意并阅读了《用户协议》和《隐私协议》"];
|
|
[lbxy setTextColor:RGBACOLOR(255, 255, 255, 0.9)];
|
|
[lbxy setTextAlignment:NSTextAlignmentLeft];
|
|
[lbxy setFont:[UIFont systemFontOfSize:12]];
|
|
[viewxy addSubview:lbxy];
|
|
[lbxy mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(btxy.mas_right).offset(0);
|
|
make.right.equalTo(lbxy).offset(-24);
|
|
make.centerY.equalTo(btxy);
|
|
make.height.offset(20);
|
|
}];
|
|
NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc]initWithString:lbxy.text];
|
|
NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
|
|
style.lineSpacing = 5;
|
|
style.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
[noteStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, lbxy.text.length)];
|
|
noteStr.yy_font = [UIFont systemFontOfSize:12.0f];
|
|
noteStr.yy_color = RGBACOLOR(255, 255, 255, 0.9);
|
|
[noteStr yy_setTextHighlightRange:NSMakeRange(8, 6) color:RGBCOLOR(240, 54, 94) backgroundColor:[UIColor whiteColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
|
|
NSLog(@"用户协议");
|
|
[self xieyiPushAction:0];
|
|
}];
|
|
[noteStr yy_setTextHighlightRange:NSMakeRange(15, 6) color:RGBCOLOR(240, 54, 94) backgroundColor:[UIColor whiteColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
|
|
NSLog(@"隐私协议");
|
|
[self xieyiPushAction:1];
|
|
}];
|
|
lbxy.attributedText = noteStr;
|
|
|
|
[viewxy mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.equalTo(lbxy);
|
|
}];
|
|
|
|
UIView *viewother= [[UIView alloc] init];
|
|
[self addSubview:viewother];
|
|
[viewother mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.offset(90);
|
|
make.bottom.equalTo(self);
|
|
make.left.right.equalTo(self);
|
|
}];
|
|
[self drawOtherView:viewother];
|
|
_viewother = viewother;
|
|
|
|
}
|
|
return self;
|
|
}
|
|
-(void)drawOtherView:(UIView *)view
|
|
{
|
|
NSArray *arrpz = [[UserInfoModel shareModel].config objectForKey:@"client.login.type"];
|
|
|
|
arrpz = @[@"weixin",@"phone"];
|
|
|
|
if(arrpz.count==0)return;
|
|
|
|
|
|
UILabel *lbname = [[UILabel alloc] init];
|
|
[lbname setText:@"其他登录方式"];
|
|
[lbname setTextColor:RGBCOLOR(170, 170, 170)];
|
|
[lbname setTextAlignment:NSTextAlignmentCenter];
|
|
[lbname setFont:[UIFont systemFontOfSize:14]];
|
|
[view addSubview:lbname];
|
|
[lbname mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.offset(0);
|
|
make.centerX.equalTo(view);
|
|
make.width.offset(95);
|
|
}];
|
|
|
|
UIView *viewlineL = [[UIView alloc] init];
|
|
[viewlineL setBackgroundColor:[UIColor clearColor]];
|
|
[view addSubview:viewlineL];
|
|
[viewlineL mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.offset(50);
|
|
make.right.equalTo(lbname.mas_left).offset(-10);
|
|
make.height.offset(1);
|
|
make.center.equalTo(lbname);
|
|
}];
|
|
|
|
UIView *viewlineR = [[UIView alloc] init];
|
|
[viewlineR setBackgroundColor:[UIColor clearColor]];
|
|
[view addSubview:viewlineR];
|
|
[viewlineR mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.equalTo(view).offset(-50);
|
|
make.width.equalTo(viewlineL);
|
|
make.height.offset(1);
|
|
make.center.equalTo(lbname);
|
|
}];
|
|
|
|
UIView *viewcollect = [[UIView alloc] init];
|
|
[view addSubview:viewcollect];
|
|
[viewcollect mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(lbname.mas_bottom);
|
|
make.bottom.equalTo(view);
|
|
make.centerX.equalTo(view);
|
|
}];
|
|
|
|
|
|
NSMutableArray *arrtmep = [NSMutableArray new];
|
|
for(NSString *str in arrpz)
|
|
{
|
|
if([str isEqualToString:@"weixin"])
|
|
{
|
|
[arrtmep addObject:@"login_wx"];
|
|
}
|
|
else if([str isEqualToString:@"phone"])
|
|
{
|
|
[arrtmep addObject:@"login_phone"];
|
|
}
|
|
}
|
|
NSArray *arr = arrtmep;
|
|
for(int i = 0 ; i < arr.count; i++)
|
|
{
|
|
UIButton *btitem = [[UIButton alloc] init];
|
|
[btitem setImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];
|
|
[viewcollect addSubview:btitem];
|
|
[btitem mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.offset(60*i);
|
|
make.top.equalTo(lbname.mas_bottom).offset(10);
|
|
make.width.offset(50);
|
|
make.height.offset(50);
|
|
}];
|
|
if([arr[i] isEqualToString:@"login_wx"])
|
|
{
|
|
[btitem setTag:1];
|
|
}
|
|
else if([arr[i] isEqualToString:@"login_phone"])
|
|
{
|
|
[btitem setTag:0];
|
|
}
|
|
|
|
[btitem addTarget:self action:@selector(otherAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
if(i==arr.count-1)
|
|
{
|
|
[viewcollect mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.equalTo(btitem);
|
|
}];
|
|
}
|
|
}
|
|
}
|
|
-(void)xieyiPushAction:(int)tag
|
|
{
|
|
WkWebviewViewController *vc = [[WkWebviewViewController alloc] init];
|
|
if(tag==1)
|
|
{
|
|
vc.strtitle = @"隐私协议";
|
|
vc.strurl = UserYinSiUrl;
|
|
}
|
|
else
|
|
{
|
|
vc.strtitle = @"用户协议";
|
|
vc.strurl = UserXieUrl;
|
|
}
|
|
[self.viewController.navigationController pushViewController:vc animated:YES];
|
|
}
|
|
-(void)xieyiAction:(UIButton *)sender
|
|
{
|
|
sender.selected = !sender.selected;
|
|
|
|
[UserInfoModel shijianShangBao:0 key:@"client.check.agreement" value:@"login" extra:[[NSString alloc] initWithFormat:@"%@",[NSNumber numberWithBool:sender.selected]]];
|
|
}
|
|
|
|
-(void)otherAction:(UIButton *)sender
|
|
{
|
|
if(self.backValue)
|
|
{
|
|
self.backValue(sender.tag);
|
|
}
|
|
}
|
|
-(void)dengluAction
|
|
{
|
|
NSString *strc = [[UserInfoModel shareModel].config objectForKey:@"client.agreement.dialog"];
|
|
if((strc.intValue == 1 || [Tools isStringnil:strc].length==0) && self.btxy.selected == NO)
|
|
{
|
|
[TongYiXieYiAlterView showName:@"温馨提示" strinfo:[NSString stringWithFormat:@"登录需要同意用户协议和隐私政策"] back:^(int type) {
|
|
[self.btxy setSelected:YES];
|
|
///
|
|
[self pushData];
|
|
}];
|
|
}
|
|
else
|
|
{
|
|
if(self.btxy.selected == NO)
|
|
{
|
|
[HXHud showMessage:@"需要同意用户协议和隐私政策" afterDelayType:0];
|
|
return;
|
|
}
|
|
[self pushData];
|
|
}
|
|
}
|
|
-(void)pushData
|
|
{
|
|
if (@available(iOS 13.0, *)) {
|
|
[LoadAlterView showView];
|
|
// 基于用户的 Apple ID 授权用户,生成用户授权请求的一种机制
|
|
ASAuthorizationAppleIDProvider *appleIdProvider = [[ASAuthorizationAppleIDProvider alloc] init];
|
|
// 创建新的 AppleID 授权请求
|
|
ASAuthorizationAppleIDRequest *request = appleIdProvider.createRequest;
|
|
// 在用户授权期间请求的联系信息
|
|
request.requestedScopes = @[ASAuthorizationScopeEmail, ASAuthorizationScopeFullName];
|
|
// 由 ASAuthorizationAppleIDProvider 创建的授权请求,管理授权请求的控制器
|
|
ASAuthorizationController *controller = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[request]];
|
|
// 设置授权控制器通知授权请求的成功与失败的代理
|
|
controller.delegate = self;
|
|
// 设置提供展示上下文的代理,在这个上下文中,系统可以向用户展示授权界面
|
|
controller.presentationContextProvider = self;
|
|
// 在控制器初始化期间启动授权流
|
|
[controller performRequests];
|
|
}
|
|
else
|
|
{
|
|
[HXHud showMessage:@"请升级手机系统" afterDelayType:0];
|
|
}
|
|
}
|
|
|
|
-(void)loginPushApple:(NSDictionary *)dic login_type:(NSString *)login_type
|
|
{
|
|
[PublicNetWorkManager requestUserLoginData:self login_type:login_type phone:@{} weixin:@{} apple:dic device:@{} onekey:@{} bind:[NSNumber numberWithBool:NO] unbind:[NSNumber numberWithBool:NO] Callback:^(BOOL state, UserLoginModel *responseObject, NSString * _Nullable describle) {
|
|
if(state)
|
|
{
|
|
[UserInfoModel setLoingState:@"1"];
|
|
[UserInfoModel setToken:responseObject.data.token];
|
|
|
|
[self pushVC];
|
|
}
|
|
else
|
|
{
|
|
[LoadAlterView dismis];
|
|
[HXHud showMessage:responseObject.message afterDelayType:1];
|
|
}
|
|
}];
|
|
}
|
|
-(void)pushVC
|
|
{
|
|
NSString *stridfa = [[NSUserDefaults standardUserDefaults] objectForKey:UserIDFA];
|
|
[PublicNetWorkManager requestUserConfigData:self idfa:stridfa Callback:^(BOOL state, UserConfigModel *responseObject, NSString * _Nullable describle) {
|
|
[LoadAlterView dismis];
|
|
if(state)
|
|
{
|
|
|
|
[UserInfoModel setToken:responseObject.data.token];
|
|
[UserInfoModel setUserid:responseObject.data.user_id];
|
|
[UserInfoModel setAppid:responseObject.data.app_id];
|
|
[UserInfoModel setRole:responseObject.data.role];
|
|
[UserInfoModel setTemp:responseObject.data.temp];
|
|
[UserInfoModel setName:responseObject.data.name];
|
|
[UserInfoModel setConfig:responseObject.data.config];
|
|
[UserInfoModel shareModel].isloadconfig = YES;
|
|
|
|
NSArray *arrtemp = self.viewController.navigationController.viewControllers;
|
|
if([arrtemp.firstObject isKindOfClass:[LoginViewController class]])
|
|
{
|
|
AppDelegate *appd = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
[appd.window setRootViewController:[TabBarController new]];
|
|
}
|
|
else
|
|
{
|
|
[self.viewController.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
|
|
[UserInfoModel getUserData];
|
|
}
|
|
else
|
|
{
|
|
[HXHud showMessage:responseObject.message afterDelayType:0];
|
|
}
|
|
}];
|
|
}
|
|
|
|
#pragma mark - ASAuthorizationController
|
|
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization {
|
|
if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) {
|
|
// 用户登录使用 ASAuthorizationAppleIDCredential
|
|
ASAuthorizationAppleIDCredential *appleIDCredential = authorization.credential;
|
|
NSString *user = appleIDCredential.user;
|
|
NSString *nickname = appleIDCredential.fullName.nickname?:appleIDCredential.email;
|
|
if([Tools isStringnil:nickname].length==0)
|
|
{
|
|
nickname = @"";
|
|
}
|
|
NSDictionary *dic = @{@"user_id":[Tools isStringnil:user],
|
|
@"user_name":nickname,
|
|
@"identify_code":[[NSString alloc] initWithData:appleIDCredential.authorizationCode encoding:NSUTF8StringEncoding],
|
|
@"identify_token":[[NSString alloc] initWithData:appleIDCredential.identityToken encoding:NSUTF8StringEncoding]};
|
|
|
|
[self loginPushApple:dic login_type:@"apple"];
|
|
|
|
} else {
|
|
NSLog(@"授权信息不符");
|
|
[LoadAlterView dismis];
|
|
|
|
}
|
|
}
|
|
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error {
|
|
|
|
NSString *errorMsg;
|
|
switch (error.code) {
|
|
case ASAuthorizationErrorUnknown: {
|
|
errorMsg = @"授权请求失败,未知原因";
|
|
break;
|
|
}
|
|
case ASAuthorizationErrorCanceled: {
|
|
errorMsg = @"用户取消了授权请求";
|
|
break;
|
|
}
|
|
case ASAuthorizationErrorInvalidResponse: {
|
|
errorMsg = @"授权请求响应无效";
|
|
break;
|
|
}
|
|
case ASAuthorizationErrorNotHandled: {
|
|
errorMsg = @"未能处理授权请求";
|
|
break;
|
|
}
|
|
case ASAuthorizationErrorFailed: {
|
|
errorMsg = @"获取授权失败";
|
|
break;
|
|
}
|
|
}
|
|
[LoadAlterView dismis];
|
|
NSLog(@"error message:%@", errorMsg);
|
|
}
|
|
#pragma mark - <ASAuthorizationControllerPresentationContextProviding>
|
|
// 告诉代理应该在哪个 window 展示内容给用户
|
|
- (ASPresentationAnchor)presentationAnchorForAuthorizationController:(ASAuthorizationController *)controller {
|
|
return self.window;
|
|
}
|
|
|
|
@end
|