没腿的鸟 发表于 2022-6-21 08:56:36

iOS 苹果集成登录及苹果图标的制作要求

前言

如果要上架的应用集成了三方登录,那么在审核时,苹果会强制要求应用也要集成苹果登录。如果应用没有集成一般情况下都会被审核团队给打回来。
苹果集成登录

首先,你需要在开发者中心,找到你的应用,勾选上 Signin with Apple
https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuLzczNWVlMzQzNGFmYjQyZjBiMTA4YzMxMWU3MTk1MGIxLnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3dhdGVybWFyayx0eXBlX1pISnZhV1J6WVc1elptRnNiR0poWTJzLHNoYWRvd181MCx0ZXh0X1ExTkVUaUJBVW1WNVdtaGhibWM9LHNpemVfMjAsY29sb3JfRkZGRkZGLHRfNzAsZ19zZSx4XzE2
勾选并保存好后, 打开Xcode, 找到项目中的Signing&Capabilities 并添加sign in with apple。
https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuLzc3YWVmZDNlN2U3NjQ0M2U4MDZhZDgzNTMwYjM0YzQ3LnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3dhdGVybWFyayx0eXBlX1pISnZhV1J6WVc1elptRnNiR0poWTJzLHNoYWRvd181MCx0ZXh0X1ExTkVUaUJBVW1WNVdtaGhibWM9LHNpemVfMjAsY29sb3JfRkZGRkZGLHRfNzAsZ19zZSx4XzE2
完成上面的配置以后,就可以写代码集成了
在进行代码集成前,需要先导入一个框架 AuthenticationServices.framework
import <AuthenticationServices/AuthenticationServices.h> 并遵守ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding协议
如果是自定义苹果按钮样式, 直接处理按钮事件
/**
苹果登录
*/
- (void)signInWithApple {
    if (@available(iOS 13.0, *)) {
            
            ASAuthorizationAppleIDProvider *provider = [ init];
            ASAuthorizationAppleIDRequest *request = ;
            request.requestedScopes = @;
            
            ASAuthorizationController *vc = [ initWithAuthorizationRequests:@];
            vc.delegate = self;
            vc.presentationContextProvider = self;
            ;
            
      }
}点击后会触发按钮事件, 接着调起苹果登录验证,验证通过后,走验证回调方法
#pragma mark 苹果集成登录
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization NS_SWIFT_NAME(authorizationController(controller:didCompleteWithAuthorization:)) API_AVAILABLE(ios(13.0)){
   
    if (])       {
      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 = [ initWithData:credential.authorizationCode encoding:NSUTF8StringEncoding]; // 验证 token
      NSString *identityToken = [ initWithData:credential.identityToken encoding:NSUTF8StringEncoding]; // 用户 token
      ASUserDetectionStatus realUserStatus = credential.realUserStatus;
      NSArray *authorizedScopes = credential.authorizedScopes;
      
      NSLog(@"state: %@\nuserID: %@\nfullName: %@\nemail: %@\nauthorizationCode: %@\nidentityToken: %@\nrealUserStatus: %@\nauthorizedScopes: %@",
            state,
            userID,
            fullName,
            email,
            authorizationCode,
            identityToken,
            @(realUserStatus),
            authorizedScopes);
      
      //苹果登录,传递认证的token
      ;
    }
}

- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)errorNS_SWIFT_NAME(authorizationController(controller:didCompleteWithError:)) API_AVAILABLE(ios(13.0)){
   
    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;
    }
    DDLogDebug(@"苹果授权失败:%@",errorMsg);
}

- (ASPresentationAnchor)presentationAnchorForAuthorizationController:(ASAuthorizationController *)controller API_AVAILABLE(ios(13.0)){
    return kAppDelegate.window;
}苹果授权验证通过后,会获取到返回的Token, 客户端拿着这个token 去调用服务器Api 来校验。 校验通过后处理用户登录的逻辑就可以了。
苹果图标的制作要求

详见:https://zhanglei.blog.csdn.net/article/details/121492572

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: iOS 苹果集成登录及苹果图标的制作要求