Perform Sign in with Apple on iOS

Tram Ho

What is Sign in with apple?

At WWDC 2019, apple introduced the Sign in with apple feature, basically, we will be able to use the existing apple ID account to log into applications, or even web sites. To make it easier to imagine, imagine a website with a Sign in with Google button or with FaceBook login, likewise, apple has developed a similar thing for them, so that we can Quick login based on your existing apple ID account without having to fill in cumbersome registration information. And with security apple says “Guaranteed”.

Ironically, for apps that have implemented third-party login functions such as logging in with goolgle, facebook, line, …, there will be a Sign In with apple required. The announcement made many comments that Apple was a bit too much. However, it still has to do because, according to many opinions, it is their competitive strategy with other parties. And the iOS brothers have a maintain, update or even tip trick to deal with. For projects that do not want to inplement this function, they can …. remove login functions with other third parties: v.

Sign in with apple on iOS

Privacy and security

  • For the first time login, the app only asks for your name and email address to set up your account
  • You can use the hidden email function, which means you can subscribe to a self-created apple email, then all information sent to this email will be fowarded to your real mail
  • Do not track, collect unnecessary information such as favorite websites, favorite apps, …
  • Allows 2-factor authentication to be enabled

We can download the Apple Sample code tutorial here

Add a Sign in with Apple button

Apple has provided a separate Button class for this button, with only 3 colors: black, white and white outline

If you want to change the color, please add the attribute]

ASAuthorizationAppleIDButton( type: .signIn, style: .whiteOutline)

Request Authorization with Apple ID

This step is the handle when clicking the Sign in with apple button

Handle User Credentials

After successful login, there will be a delegate function (ASAuthorizationControllerDelegate) so we can get the requested information returned.

If we choose to hide the email then the email will be private, and the notifications will be fowarded to the real mail. If the pulish mail is available, it can be obtained from the data returned in the delegate

Request Existing Credentials

It is not necessary to press the button to request information, we can completely refresh, call each time the view reloads When the view loads, call the following function.

Check User Credentials at Launch

The handling of auto login with the previous account. Just save the UserIdentifier information when the request is informed, and call the following function in Appdelegate, you can handle it easily.

Thank you for reading my article, hope to help you!


Share the news now

Source : Viblo