评论

收藏

[iOS开发] iOS 苹果集成登录及苹果图标的制作要求

移动开发 移动开发 发布于:2022-05-11 17:29 | 阅读数:481 | 评论:0

前言
如果要上架的应用集成了三方登录,那么在审核时,苹果会强制要求应用也要集成苹果登录。如果应用没有集成一般情况下都会被审核团队给打回来。
苹果集成登录
首先,你需要在开发者中心,找到你的应用,勾选上 Sign  in with Apple
DSC0000.jpg
勾选并保存好后, 打开Xcode, 找到项目中的Signing&Capabilities 并添加sign in with apple。
DSC0001.jpg

完成上面的配置以后,就可以写代码集成了
在进行代码集成前,需要先导入一个框架 AuthenticationServices.framework
import <AuthenticationServices/AuthenticationServices.h>
并遵守ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding协议
如果是自定义苹果按钮样式, 直接处理按钮事件
/**
 苹果登录
 */
- (void)signInWithApple {
  if (@available(iOS 13.0, *)) {
      
      ASAuthorizationAppleIDProvider *provider = [[ASAuthorizationAppleIDProvider alloc] init];
      ASAuthorizationAppleIDRequest *request = [provider createRequest];
      request.requestedScopes = @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail];
      
      ASAuthorizationController *vc = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[request]];
      vc.delegate = self;
      vc.presentationContextProvider = self;
      [vc performRequests];
      
    }
}
点击后会触发按钮事件, 接着调起苹果登录验证,验证通过后,走验证回调方法
#pragma mark 苹果集成登录
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization NS_SWIFT_NAME(authorizationController(controller:didCompleteWithAuthorization:)) API_AVAILABLE(ios(13.0)){
  
  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(@"state: %@\nuserID: %@\nfullName: %@\nemail: %@\nauthorizationCode: %@\nidentityToken: %@\nrealUserStatus: %@\nauthorizedScopes: %@",
        state,
        userID,
        fullName,
        email,
        authorizationCode,
        identityToken,
        @(realUserStatus),
        authorizedScopes);
    
    //苹果登录,传递认证的token
    [self loginWithAppleToken:token];
  }
}
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error  NS_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

本文来自博客园,作者:reyzhang,转载请注明原文链接:https://www.cnblogs.com/reyzhang/p/16199135.html


   
   
   
                        

关注下面的标签,发现更多相似文章