SwiftUI provides an easy way to add Sign in with Apple
(SIWA) button using the view SignInWithAppleButton from Authentication Services framework
The SIWA button can be added in a similar way like how you add a normal SwiftUI Button
1
2
3
4
5
6
7
8
9
SignInWithAppleButton(.signIn) {
// Provides `ASAuthorizationAppleIDRequest` that can be used
// to set the requestedScopes, user, nonce etc.
$0.requestedScopes = [.email, .fullName]
} onCompletion: { result in
// Completion handler which returns `Result<ASAuthorization, Error>`
// when the sign in completes.
}
.frame(width: 206, height: 44)
SIWA button accepts a label as the first parameter which determines the text to be shown on the button. The style for the button can be configured using SignInWithAppleButton.Style
1
.signInWithAppleButtonStyle(.white)
SIWA button doesn’t seems to have an intrinsic size and is expected to set a proper frame to avoid displaying it in weird shapes. The button can be configured and styled according to the customer experience requirement following the Human Interface Guidelines