123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- //
- // SettingsViewController.swift
- // AIPaint
- //
- // Created by Fengyu He on 2022/11/29.
- //
- import UIKit
- import SnapKit
- import AuthenticationServices
- class SettingsViewController: UIViewController {
-
- let welcomeView: UIView = {
- var view = UIView()
- view.layer.borderWidth = 1
- view.layer.borderColor = UIColor.systemGray.cgColor
- view.layer.cornerRadius = 14
- return view
- }()
-
- lazy var welcomeText: UILabel = {
- var label = UILabel()
- label.numberOfLines = 0
- label.lineBreakMode = .byWordWrapping
- label.text = "感谢你参与画酱的封闭测试,见证画酱的诞生!\n你可以加入QQ群来对本 App 提出宝贵意见:390674039 \n此 App 目前还在初期稳定行测试阶段,如果你有什么功能上的需求,或是对于 App 的设计有任何的建议,欢迎进群与我讨论!\n \n暂时还没适配暗黑模式,请在正常模式使用此 App。"
- return label
- }()
-
- var signInWithAppleButton = ASAuthorizationAppleIDButton(authorizationButtonType: .default, authorizationButtonStyle: .black)
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- if UITraitCollection.current.userInterfaceStyle == .dark {
- view.backgroundColor = .black
- } else {
- view.backgroundColor = .white
- }
- self.title = "设置"
- signInWithAppleButton.cornerRadius = 8.0
- signInWithAppleButton.addTarget(self, action: #selector(loginButtonTapped), for: .touchUpInside)
- view.addSubview(signInWithAppleButton)
-
- if #available(iOS 15.0, *) {
- signInWithAppleButton.isHidden = false
- } else {
- signInWithAppleButton.isHidden = true
- }
-
- view.addSubview(welcomeView)
- welcomeView.addSubview(welcomeText)
-
- welcomeView.snp.makeConstraints { (make) in
- make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(5)
- make.centerX.equalTo(view.safeAreaLayoutGuide.snp.centerX)
- make.width.equalTo(view.safeAreaLayoutGuide.snp.width).multipliedBy(0.95)
- make.height.equalTo(view.safeAreaLayoutGuide.snp.height).multipliedBy(0.35)
- }
-
- welcomeText.snp.makeConstraints { (make) in
- make.top.equalTo(welcomeView.snp.top).offset(5)
- make.centerX.equalTo(welcomeView.snp.centerX)
- make.width.equalTo(welcomeView.snp.width).multipliedBy(0.9)
- make.height.equalTo(welcomeView.snp.height).multipliedBy(0.98)
- }
- }
-
- @objc func loginButtonTapped() {
- if #available(iOS 15.0, *) {
- let provider = ASAuthorizationAppleIDProvider()
- let request = provider.createRequest()
- request.requestedScopes = [.email, .fullName]
- let controller = ASAuthorizationController(authorizationRequests: [request])
- controller.delegate = self
- // controller.presentationContextProvider = self
- controller.performRequests()
- }
- }
- }
- extension SettingsViewController: ASAuthorizationControllerDelegate {
- @available(iOS 15.0, *)
- func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
- do {
- //苹果用户唯一标识符,该值在同一个开发者账号下的所有 App 下是一样的,开发者可以用该唯一标识符与自己后台系统的账号体系绑定起来。
- var credential = authorization.credential as! ASAuthorizationAppleIDCredential
- let userID = credential.user
- let fullName = credential.fullName
- let identifierToken = credential.identityToken
- }
-
-
- func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
- print("Login Error")
- }
-
- func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
- return view.window!
- }
- }
- }
- //extension SettingsViewController: ASAuthorizationControllerPresentationContextProviding {
- // func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
- //
- // }
- //}
|