As shown at WWDC 2020, Apple has made it even easier to implement Apple Sign In. By simply calling the struct, you will be able to have Apple Sign In right on your screen.

“A control that you add to your interface to allow users to sign in with their Apple ID.” — Apple’s documentation


Prerequisites

To follow along with this tutorial, you’ll need some basic knowledge in:

  • Swift
  • At least Xcode 12+

Note: This only supports iOS 14+.


SignInWithAppleButton

You may indicate if you would like to be a signup or a sign-in. Here, you will be doing a sign-in:

SignInWithAppleButton(
	    .signIn,
	    onRequest: { request in
	        // 1
	        request.requestedScopes = [.fullName, .email]
	    },
	    onCompletion: { result in
	        switch result {
	        case .success (let authResults):
	            // 2
	            print("Authorization successful.")
	        case .failure (let error):
	            // 3
	            print("Authorization failed: " + error.localizedDescription)
	        }
	    }
	).frame(width: 200, height: 30)
  1. The request scope is where you can specify what kind of information you would like to collect from the user. Currently, you are only collecting the full name and email address.
  2. Authentication is successful. Here, you will be able to get the credentials and information to store in your database.
  3. If the authentication fails, you will be able to identify the error with the provided description.

#ios #swiftui #mobile #swift #programming

New: A SignInWithAppleButton in SwiftUI
28.40 GEEK