iOS 13 provides a way to authenticate users in applications by using their Apple Id account. In this post, I will show you how to implement this in a Xamarin Forms project.
Let’s start!
1. In the Apple portal, enable Sign In with Apple in your App Identifier
2. Enable Sign in with Apple on the Entitlement.plist file.
3. Create the sign in with apple service interface
4. Create the class that will represent the apple account model and an enum for the credential states.
5. Implement the sign in with apple service in the iOS project
6. Create a sign in with apple button control, which will be used in our XAML
7. Create a custom renderer to be able to use the native button for Apple sign in
8. Implement our ViewModel to call the apple sign in service when apple sign in command gets executed
9. We will use the apple sign in button in our XAML and just make it visible if the feature is available.
10. On App.cs when the application starts you need to be aware of checking the status for apple sign in, to handle properly the current credentials state.
Important Notes
- Apple will only provide you the requested details on the first authentication. After that first authentication, you will only get the User Id so be sure to store the details that first time in case you need them.
- This feature needs to be tested on a physical device running iOS 13. The simulator is not reliable, it doesn’t always work properly.
- Should follow the design guidelines when implementing Apple Sign In. You can find it here: https://developer.apple.com/design/human-interface-guidelines/sign-in-with-apple/overview/
You can check the full source code here.
If you need to support sign in with apple in other platforms such As android, web or earlier iOS versions. You can check this awesome sample by Jonathan Dick.
Happy sign in with apple!
References
https://docs.microsoft.com/en-us/xamarin/ios/platform/ios13/sign-in
https://github.com/Redth/Xamarin.AppleSignIn.Sample
https://www.raywenderlich.com/4875322-sign-in-with-apple-using-swiftui