Sign in with Apple in the iOS App

Jaydeep Vora
4 min readAug 4, 2019

--

Introduction

Till now we had heard about the login with Facebook and Gmail and another platform, But now Apple also dives into this feature, With iOS 13 they decide to start providing an easy, fast and safe way to login with your apple account in-app.

It works on iOS, macOS, tvOS, and watchOS. We can also add Sign in with Apple to Website and other mobile platforms.

If we look at the security perspective, Sign in with Apple provides a better option for user and developer then other Third-party login platforms where they failed security and privacy breaches.

I’m excited to know

Integrate “Sign in with Apple” in the iOS App

Yes, I know that you are excited to see this feature in your iOS app, Ok then we are gonna implement in our app.

1) Setup Sign in with Apple in project

Now, open Xcode 11 and then create the project, Hope it's easy for you that why I’m not going deep in this.

  • Now add Sign in with Apple capability in your App, to do this Go to “Target” and click on “Capability”
Add Sign in with Apple in Capability
  • Now enable this Sign in with Apple capability in app identifier in AppStore Connect. Certificates, Identifiers & Profiles IdentifiersIdentifiers → You app identifier
Add Sign in with Apple in application identifier
  • Also, add Keys for Apple Sign in, For that Go to Certificates, Identifiers & Profiles IdentifiersKeys→ Create Key
Create keys for Sign in with Apple
  • Enter the name of keys and don’t forget to check Sign in with Apple option. after that click on the configure button in the same line and choose our app bundle id.
Register for Sign in with apple and configure the key
Choose app bundle id

Now after selecting the bundle id, Save the process and Register the Key.

2) Let’s do the Code

  • Open ViewController and add below code
Setup the Sign-in button and Add event on the button.

Above code contains a method setupAppleSignIn, It will setup Apple Sign in button in View of ViewController. I had also added target for the ASAuthorizationAppleIDButton Control called appleSigninTapped().

In appleSigninTapped event ASAuthorizationAppleIDProvider class generates the request to authenticate the user based on their Apple ID. ASAuthorizationAppleIDRequest create the request and defined contact information scope using .fullName and .email.

Now we created the request object so we have to just pass the object to ASAuthorizationController, And set presenter and delegate to self (current ViewController). Now we are finally ready to show the UI for Apple sign in for that just call performRequests() method of ASAuthorizationController.

Still getting Error.

Wait Wait, I know you are still got Error, we are just one step ahead, Remeber we had assigned the delegate and presenter to self, So we have to implement the ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding methods.

Now in the above code, ASAuthorizationControllerDelegate has 2 methods to decide whether an authorization is completed or failed.

To present the Authorization controller you can use presentationAnchor(for controller: ASAuthorizationController) method. In which you have to provide the anchor window.

And now the code is error-free, We can run the app and check the feature. it will show Sign in with apple button in the center of the screen.

When you tap on the button it will open the popup with Apple ID information. you can continue to login.

To add the Sign in with Apple button in your design you must have to consider Human Interface Guidelines: Sign In with Apple.

And for privacy concern App Store Review Guidelines: Privacy you can visit this link.

Done, That’s it

Hope you found helpful information from this article If you love this article make some clap. or if you have any query write in comment.

--

--

Jaydeep Vora
Jaydeep Vora

Written by Jaydeep Vora

iOS | Swift | Flutter | SwiftUI, Let’s grow together | LinkedIn — https://www.linkedin.com/in/jaydeep-vora | Skype — jaydeep.33

No responses yet