苹果版赤潮可以用微信登陆吗

Let’s recreate “Sign in with Apple” Button for our app in SwiftUI. Before that, let us get some terms out of the way

让我们在SwiftUI中为我们的应用程序重新创建“使用Apple登录”按钮。 在此之前,让我们摆脱一些限制

SwiftUI is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift. Build user interfaces for any Apple device using just one set of tools and APIs.” — Apple’s official documentation

SwiftUI是一种创新的,非常简单的方法,可以借助Swift跨所有Apple平台构建用户界面。 仅使用一组工具和API为任何Apple设备构建用户界面。” — 苹果官方文档

The best part is you can integrate your views with components from the UIKit, AppKit, and WatchKit frameworks. In short, SwiftUI has made building user interfaces straightforward.

最好的部分是您可以将视图与UIKit,AppKit和WatchKit框架中的组件集成在一起。 简而言之,SwiftUI使构建用户界面变得简单明了。

“Sign In with Apple is the fast, easy, and more private way to sign into apps and websites using the Apple ID that you already have.” — Apple’s official documentation

“使用Apple登录是一种使用您已经拥有的Apple ID登录应用和网站的快速,简便,私密的方式。” — 苹果官方文档

为什么使用Apple登录很重要? (Why Sign In with Apple is Important?)

  1. Apple would soon make every developer use Sign in with Apple mandatory. In sum, you don’t have another option.Apple很快将使每个开发人员都必须使用Apple登录。 总之,您没有其他选择。
  2. Sign in with Apple is built from the ground up to respect user’s privacy and keep them in control of their personal information.使用Apple登录是从头开始的,旨在尊重用户的隐私并控制他们的个人信息。
  3. Instead of using a social media account, or filling out forms and choosing another new password, just tap the Sign in with Apple button, review your information, and sign in quickly and securely with Face ID, Touch ID, or the device passcode.无需使用社交媒体帐户或填写表格并选择其他新密码,只需点击“使用Apple登录”按钮,查看您的信息,然后使用Face ID,Touch ID或设备密码快速安全地登录即可。
  4. Sign in with Apple does not track or profile users as they favorite apps and websites, and Apple retains only the information that’s needed to make sure they can sign in and manage your account.

    使用Apple登录不会跟踪用户喜欢的应用程序和网站,也不会对他们进行配置,Apple仅保留确保他们可以登录和管理您的帐户所需的信息。

Without further wait, let us get on how you could implement Sign In with Apple in SwiftUI. Before you begin, you need to add “Sign In with Apple” Capability in Xcode. To do that,

不用再等待了,让我们开始了解如何在SwiftUI中使用Apple实现登录。 在开始之前,您需要在Xcode中添加“使用Apple登录”功能。 要做到这一点,

  1. Click on your project点击你的项目
  2. Go to Signing and Capabilities转到签名和功能
  3. Click “+” sign and search for “Sign In with Apple” and select it.单击“ +”号,然后搜索“使用Apple登录”并选择它。

That’s it, we are ready to implement Sign In With Apple. Now lets’ look at the code.

就是这样,我们已经准备好实现与Apple一起登录。 现在让我们看一下代码。

SwiftUI does not provide an AppleIdButton so let’s just start there. We would need to wrap one up ourselves. Here, we are simply wrapping ASAuthorizationAppleIdButton, so we could use it in SwiftUI

SwiftUI没有提供AppleIdButton,所以让我们从这里开始。 我们需要自己包一个。 在这里,我们只是包装了ASAuthorizationAppleIdButton,所以我们可以在SwiftUI中使用它

struct AppleIdButton: UIViewRepresentable {func makeUIView(context: Context) -> ASAuthorizationAppleIDButton {ASAuthorizationAppleIDButton()}func updateUIView(_ uiView: ASAuthorizationAppleIDButton, context: Context) {}
}

At this point, in your ContentView, you should be able to render the official Apple Button like this,

此时,在ContentView中,您应该能够像这样渲染官方Apple Button,

Button (action: {}) {  AppleIdButton()}//May be style it a little AppleIdButton().background(Color.primary).clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous)).padding(7).frame(width: UIScreen.main.bounds.width - 100, height: 65)

Let’s go back to AuthenticationService. Make sure you have AuthenticationServices imported. It provides a framework for handling Authorization requests. Next, we need to work on the Coordinator. This coordinator provides a mechanism to request Apple to register a new user, or sign in an existing user.

让我们回到AuthenticationService。 确保已导入AuthenticationServices。 它提供了一个处理授权请求的框架。 接下来,我们需要协调员。 该协调器提供了一种机制,可以请求Apple注册新用户或登录现有用户。

Coordinator to help the create request to Apple
协调员,以帮助向Apple创建请求

Lets look at this code closely:

让我们仔细看一下这段代码:

  1. First, we create a request with AppleIDProvider and we request the user’s full name and email. One thing to note here is that this is optional and you can choose if you want to store this data or not.首先,我们使用AppleIDProvider创建一个请求,并请求用户的全名和电子邮件。 这里要注意的一件事是这是可选的,您可以选择是否要存储此数据。
  2. Next, we initialize the ASAuthorizationController with the request we build in the first step and execute our request for user registration or sign in.接下来,我们使用第一步中构建的请求初始化ASAuthorizationController,并执行我们的用户注册或登录请求。
  3. We need access to ASAuthorizationControllerDelegate protocol to be able to have access to delegate function to fetch verification (success or failure here)我们需要访问ASAuthorizationControllerDelegate协议才能访问委托函数以获取验证(此处成功或失败)
  4. didCompleteWithAuthorization: Once the user is successfully signed in, it checks is the credential is ASAuthorizationAppleIdCredential. If yes, this function returns the name and email of the user. While you should be storing this is in the Keychain (more secure), we are just storing it in UserDefaults.

    didCompleteWithAuthorization:成功登录用户后,它将检查凭据是否为ASAuthorizationAppleIdCredential。 如果是,则此函数返回用户的名称和电子邮件。 当您将其存储在钥匙串中(更安全)时,我们只是将其存储在UserDefaults中。

  5. didCompleteWithError: It is important to handle this case, where the sign-in fails and we return a localized description of the error.

    didCompleteWithError:处理这种情况很重要,因为这种情况登录失败,并且我们返回错误的本地化描述。

If you noticed that we have saved the user in our UserDefault. Therefore, before getting here, we should check if the user is already signed in. This will keep user logged in until they choose to sign out manually. To achieve this, we will write a wrapper on top of getAppleRequest() to check if the user is already logged in.

如果您注意到我们已将用户保存在UserDefault中。 因此,在到达此处之前,我们应该检查用户是否已经登录。这将使用户保持登录状态,直到他们选择手动注销为止。 为此,我们将在getAppleRequest()顶部编写一个包装器,以检查用户是否已经登录。

func getUserInfo() {if let userData = UserDefaults.standard.object(forKey: "user")                as? Data,let userDecoded = try? JSONDecoder().decode(User.self, from:  userData) {      print("UserData: \(userDecoded)")      user = userDecoded   }}

Let’s clean up our code a little by creating a ViewModel that our ContentView can communicate with:

让我们通过创建一个我们的View可以与之通信的ViewModel来稍微整理一下代码:

final class AppleViewModel: ObservableObject {var signInWithApple = SignInWithAppleCoordinator()@Published var user: User?func getRequest() {signInWithApple.getApppleRequest()}func getUserInfo() {if let userData = UserDefaults.standard.object(forKey: "user") as? Data,let userDecoded = try? JSONDecoder().decode(User.self, from: userData) {print("UserData: \(userDecoded)")user = userDecoded}}
}

Finally, from our View, we create an AppleIdButton. With this, you should be able to route the user to your app if the user is already logged in.

最后,从视图中创建一个AppleIdButton。 这样,如果用户已经登录,则应该能够将用户路由到您的应用。

struct Login: View {@ObservedObject var appleView = AppleViewModel()var body: some View {VStack {if appleView.user != nil {//User Logged In} else {Button(action: {self.appleView.getRequest()}){AppleIdButton().background(Color.primary).clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous)).padding(7).frame(width: UIScreen.main.bounds.width - 100, height: 65)}}.onAppear( perform: {self.appleView.getUserInfo()})}
}

That’s it! Now you have “Sign In with Apple” built into your app.

而已! 现在,您的应用程序已内置“使用Apple登录”。

Thanks for reading!

谢谢阅读!

翻译自: https://medium.com/swlh/sign-in-with-apple-in-swiftui-1b1d3e62850b

苹果版赤潮可以用微信登陆吗


http://www.taodudu.cc/news/show-4106230.html

相关文章:

  • 知乎周源微信_每周源代码16-风管磁带版
  • iOS逆向(7)-LLDB,自制LLDB脚本,窜改微信红包金额
  • Ubuntu 常用软件推荐(QQ、微信、MATLAB等)及安装过程
  • 微信小程序选择图片优化_如何选择完美的图像格式来优化您的网站
  • 微信限制收付款怎么解决_解决付款处理问题
  • 微信开发工具取消域名检查_如何检查域名可用性(简易域名搜索工具)
  • linux 监控微信通知,Prometheus + Altermanager实现告警微信通知
  • 高项笔记1.信息化和信息系统
  • 信息系统项目管理重点:信息化发展原则和方向
  • 企业管理信息系统成功实施的四个阶段
  • 数字化转型:信息系统的生命周期(一)
  • 笔记-中项/高项学习期间的错题笔记2
  • 隐马尔科夫模型(HMM)学习笔记二
  • .net面式题
  • linux学习记录(二)
  • kernel启动流程第二阶段
  • RxJava操作符(09-算术/聚合操作连接操作)
  • Android 函数响应式编程(RxJava3)
  • PMP/高项 项目范围管理实践
  • 高项_第九章人力资源管理
  • 手写demo了解vue响应式原理,订阅模式,观察者模式
  • 二看 Vue
  • logistic regression(二项 logistic 与 多项logistic )
  • 高项十大管理
  • 基于连续优化的规划算法:以二次规划为例
  • 《第三节》解读Logback的配置文件
  • 2022-2028中国蛋白糖果市场现状研究分析与发展前景预测报告
  • PHP微信公众号登录获取openid信息
  • vue.js微信公众号登录,获取当前用户openid等基本信息
  • 微信公众号登录的一些注意事项

苹果版赤潮可以用微信登陆吗_用swiftui中的苹果登录相关推荐

  1. ajax 微信code获取_计算机毕业设计中微信小程序实现微信登录(Java后台)

    点击上方"蓝字",关注我们. 需要的材料 1:一个可以测试的微信小程序 2:此微信小程序的APPID和APPscret 流程 微信用户对应一个小程序都有一个唯一的openid,微信 ...

  2. java音乐登陆界面_第四篇——Spring音乐登录界面设计及实现(C#)

    Spring音乐播放器,我们小组设计其启动时有一个登录界面,用户初次可以注册,输入用户名和密码,点击注册即将输入信息保存到register文本文件中:如果已有用户名,输入用户名和密码,点击登录,程序会 ...

  3. cornerRadius (_:antialiased:) (SwiftUI 中文文档手册)

    cornerRadius(_:antialiased:) 将此视图剪切到具有指定角半径的边界框. func cornerRadius(_ radius: CGFloat, antialiased: B ...

  4. python实现qq登录_在django中实现QQ登录

    在服务器端做qq登录的流程: 1.放置QQ登录按钮,这个去QQ的网站上下,把这个按钮的连接指向 https://graph.qq.com/oauth2.0/authorize?response_typ ...

  5. token 微信access 过期_如何设计 QQ、微信等第三方账号登陆 ?以及设计数据库表!...

    来源:http://suo.im/5SBVka 多账户的统一登录 名称解释 这里的多账户区别于系统级别的,我们讲的多账户系统是指,在我们互联网应用当中,我们的应用会使用多个第三方账号进行登录,比如现在 ...

  6. 抖音微信登录服务器繁忙,抖音无法正常使用微信登录_抖音微信登陆失败解决方法_游戏吧...

    抖音出现了无法正常使用微信登陆的问题,很多小伙伴都非常的苦恼,这到底是怎么回事呢?下面游戏吧小编就为各位玩家带来了抖音微信登陆失败解决方法. 抖音微信登陆失败解决方法 1.登录的时候没有同意授权; 2 ...

  7. 微信小程序_(校园视)开发视频的展示页_上

    微信小程序_(校园视) 开发用户注册登陆 传送门 微信小程序_(校园视) 开发上传视频业务 传送门 微信小程序_(校园视) 开发视频的展示页-上 传送门 微信小程序_(校园视) 开发视频的展示页-下 ...

  8. 完整的微信登陆 接收消息流程

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 1. G ...

  9. uniapp授权微信登陆

    uniapp授权微信登陆 测试平台安卓 工具 安卓模拟器(网易的mumu) 打包工具(HBuilderX) 微信签名生成工具 首先微信授权的appid和签名确保与项目保持一致 通过签名工具获取到签名 ...

  10. openid java_微信小程序调用微信登陆获取openid及java做为服务端示例

    一.微信小程序 第一步:调用 wx.login获取code 文档地址 第二步:判断用户是否授权读取用户信息 文档地址 第三步:调用wx.getUserInfo读取用户数据 文档地址 第四步:由于小程序 ...

最新文章

  1. IntelliJ IDEA 12 创建Web项目 教程 超详细版
  2. 【Flutter】如何写一个Flutter自动打包成iOS代码模块的脚本
  3. Tomcat7并发和线程数
  4. C# numericUpDown控件用法总结及注意事项
  5. 一文搞懂 Java 线程中断
  6. 在html页面中使用模板继承,HTML静态模板的继承
  7. android ndk 编译选项,Android NDK 对于c++的支持(mk文件内编译选项)
  8. 关于NGINX下开启PHP-FPM 输出PHP错误日志的设置(已解决)
  9. 线程池----ThreadPoolExecutor
  10. 项目怎么导入mui_Vue项目MUI的使用
  11. UReport2 报表设计器 在线表格
  12. HTML语言的三要素,web前端基础技术三要素HTML、CSS、JavaScript
  13. php js 获取 客户端ip地址,JavaScript获取客户端IP的方法(新方法)
  14. SonarLint 默认扫描规则
  15. 关于总时差和自由时差的作用及理由
  16. 计算机重装系统桌面文件如何恢复,电脑重装系统后桌面文件如何恢复-万兴恢复专家...
  17. “伊”心一意研技术,“伊”丝不苟做服务。Electropure EDI 成功参展第12届上海国际水展
  18. 怎么看计算机网络通不通,网络不通应该怎么检查?
  19. 计算机证英语四六级证驾驶证,学校毕业要求有两个技能证书,计算机二级,四六级,到底算不算技能证?...
  20. 三菱PLC以太网MC通讯协议模块

热门文章

  1. 使OEM分区变成可格式化
  2. 推荐一款云服务器免费试用,可以延期再使用
  3. MA5680T配置指导
  4. 阳了之后,北京人纷纷化身段子手 !
  5. (十)DSP28335基础教程——ECAP实验(超声波测距)
  6. 将ui文件转换为py文件
  7. GCC编译过程及使用
  8. 《Hibernate上课笔记》------class6------Hibernate实现一对多关联映射
  9. Z世代成为消费新主力,我国潮牌营销洞察报告​
  10. c语言链表中next作用,C语言链表中q-next=p;表示什么意思?