苹果登录集成 Sign in with Apple

您所在的位置:网站首页 iphone账号授权 苹果登录集成 Sign in with Apple

苹果登录集成 Sign in with Apple

2023-09-10 15:21| 来源: 网络整理| 查看: 265

原创: 前行哲 iOS知识分享 今天

通过本文,你将了解到是否需要集成 Sign in with Apple 功能,以及如何集成 Sign in with Apple 功能。

本文主要讲解以下内容

∙ 概览 ∙ 集成

概览

在 WWDC 2019 上,苹果推出了自家的 Sign in with Apple 功能,这很 Apple。可能苹果看到第三方登录百家争鸣,琢磨着自己也搞了个,这对很多第三方登录来说可能是个威胁。 现在如果app中集成了第三方登录必须支持apple登录,不然就会被拒4.8,所以集成apple登录势在必行。 苹果对 Sign in with Apple 的介绍:

Sign In with Apple makes it easy for users to sign in to your apps and websites using their Apple ID. Instead of filling out forms, verifying email addresses, and choosing new passwords, they can use Sign In with Apple to set up an account and start using your app right away. All accounts are protected with two-factor authentication for superior security, and Apple will not track users’ activity in your app or website. 使用 Sign in with Apple 会更加方便、快捷、安全,苹果不会追踪用户在应用中的行为。所以,对于用户来说使用 Sign in with Apple 会更加安全。

另外,􏰎􏰏􏰐Sign in with Apple 支持跨平台

∙ Native SDK 支持􏲟􏲠 iOS/MacOS/watchOS/tvOS ∙ Javascript SDK 支持 Android, Windows, Web 话说这个 iOS 13 才支持的功能,我们有必要集成吗?🤔

看了下面这句话,你或许就有答案了。

Sign In with Apple will be available for beta testing this summer. It will be required as an option for users in apps that support third-party sign-in when it is commercially available later this year. 简单来说,如果你的 App 没有提供第三方登录,那就不用集成。如果用到了第三方登录,那么需要提供 Sign in with Apple。

集成

集成 需要以下几个步骤:

image 一、准备工作

开启 Sign in with Apple 功能

登录开发者网站,在需要添加 Sign in with Apple 功能的 Identifier 开启功能。 image Xcode 里面 Signing & Capabilities 开启 Sign in with Apple 功能。 image 二、代码集成

Talk is cheap. Show me the code!😌

创建登录按钮 官方提供了一个 ASAuthorizationAppleIDButton (继承自UIControl),使用这个来创建一个登录按钮。 [button addTarget:self action:@selector(signInWithApple) forControlEvents:UIControlEventTouchUpInside]; button.center = self.view.center; [self.view addSubview:button];

这个按钮具有两种文案类型和三个样式,分别是:

typedef NS_ENUM(NSInteger, ASAuthorizationAppleIDButtonType) { ASAuthorizationAppleIDButtonTypeSignIn, ASAuthorizationAppleIDButtonTypeContinue, ASAuthorizationAppleIDButtonTypeDefault = ASAuthorizationAppleIDButtonTypeSignIn, } typedef NS_ENUM(NSInteger, ASAuthorizationAppleIDButtonStyle) { ASAuthorizationAppleIDButtonStyleWhite, ASAuthorizationAppleIDButtonStyleWhiteOutline, ASAuthorizationAppleIDButtonStyleBlack, }

通过图片可能更直观

image

从图上可以看出:

∙ Apple 提供的登录按钮有三种外观:白色,带有黑色轮廓线的白色和黑色。 ∙ 文案有两种:Sign In with Apple 和 Continue with Apple。(具体使用哪个文案,根据自身业务需求来定) 另外,按钮宽高默认值为 {width:130, height:30}。

对于 ASAuthorizationAppleIDButton 我们能够自定义的东西比较少,比如背景色不能更改,文案只有两种可选,并且值不能修改,可以调整的只有圆角cornerRadius和size 。

image

宽高也有一定限制:

Minimum width Minimum height Minimum margin 140pt (140px @1x, 280px @2x) 30pt (30px @1x, 60px @2x) 1/10 of the button's height

具体的设计规范,请参考:Human Interface Guidelines

通过调整 size 发现还有个新花样。比如这样: image

是不是发现文字没有了,当然有些童鞋可能会说,变成圆形的了。嗯,圆形还是比较简单设置的,主要的变化还是文字。同时,我们还可以发现,在这种情况下,调大尺寸,里面的苹果 logo 也会跟着变大,适应展示。具体怎么操作,看下面:

ASAuthorizationAppleIDButton *button = [ASAuthorizationAppleIDButton buttonWithType:ASAuthorizationAppleIDButtonTypeContinue style:ASAuthorizationAppleIDButtonStyleBlack]; button.bounds = CGRectMake(0, 0, 40, 40); button.cornerRadius = 20.0f;

不过上面这种方式,不知道审核是否可以通过哈,大家还是慎用,仅作为一种参考。不过,苹果貌似没有强制使用默认的登录按钮。

To help people set up an account and sign in, it's best to use the familiar buttons that Apple provides for Sign In with Apple. 再补充一点,通过上面这种修改 size 后,会收到布局警告⚠️,通过警告信息,大致可以看出来,按钮宽度的范围是:>= 130px,高度范围是:>=30px &&



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3