Sign in with Apple using SwiftUI |

Learn how to implement Sign in with Apple using SwiftUI, to give users more privacy and control in your iOS apps.

This is a companion discussion topic for the original entry at

None of the previews work for the SwiftUI files that come in the sample project. I have this problem with the sample projects for Apple’s tutorials, too. The error I get for ContentView is

‘ContentView’ is not a member type of ‘SignInWithApple’

Does anyone know a solution to this error?
I am on Xcode 11 and Catalina beta 9.

Are you using the release version of Xcode 11? There were issues in previous versions of Xcode that did goofy things with the ContentView, especially if any of your folders had a space in the name. I just download the project files from the post and was able to successfully build and look at the ContentView in both the starter and final projects once I set my bundle identifier.

Great tutorial. For testing purposes I was testing it without asking for FullName and logged in a couple of times with my Apple ID. Now I want to change it to ask for full name but the request won’t kick in. Already deleted the App and also deleted the access to it from my Apple Id on iCloud. Still it won’t prompt. Is there anything I can do to get the pop up back up?

The way to do this is go to setting, tap on your apple id at the top, choose Password & Security, then Apps Using Apple ID. From there you should be able to choose your app and “Stop Using Apple ID” for it. After you do that it’ll prompt you like it’s the first time.

Thanks. This was buggy two days ago, in the sense I removed and iOS wouldn’t still ask but seem to be fine now. The webcredentials for the keychain is off now. Not working at all. Plus, the face id pop up request for the Apple Sign In does not pop sometimes (you have to slightly force it by doing a swipe up).
Its kinda weird right now. Your tutorial is helping me understand it better.

By the way, the keychain wrapper you use in the example. Is it a cocoapod? Is it fine if I use?
It seems to be one the bests I saw around cause it allows for try/catches, the other from Ray just returns a Bool.

Nope, it’s just a file that I wrote. You can freely copy it as long as you keep the copyright header in tact.

@gargoyle, thanks for the tutorial, it’s really useful!
You mentioned OAuth setup with Sign In with Apple. Any plans for tutorial about it?

@max.vyshnevskyi Glad to hear you found it useful! I do plan on writing a tutorial around using this server side with OAuth. However, there’s a bug right now with Apple’s REST API where they are ignoring the expiration date passed and the returned token is only good for 9 minutes. I have an open bug with them, but they just keep asking for a ‘sysdiagnose’ even though this has nothing to do with a Mac. I’ve sent them explicit ‘curl’ commands now showing how this is done from a non-mac windows machine, but I haven’t heard back from them.

@gargoyle, I see… So good luck with that and I’m looking forward to the new tutorial :slight_smile:

I ran the app on a device running iOS 13.3 and even though the modal for logging in with my Apple ID shows, the app does not progress past the sign in screen once I successfully log in with my Apple ID. I compiled the app using XCode 11.2.1

Hi @jtremain. The app isn’t designed to do anything after you’ve successfully authenticated. It’s just showing you how to authenticate. You’ll just do normal SwiftUI type stuff to handle your navigation after you’ve attempted the authentication.

I have a problem with storing data to the keychain. I always get the following error:

Error Domain=NSCocoaErrorDomain Code=4866 “The data couldn’t be written because it isn’t in the correct format.” UserInfo={NSUnderlyingError=0x2815af720 {Error Domain=NSCocoaErrorDomain Code=4864 “This decoder will only decode classes that adopt NSSecureCoding. Class ‘__SwiftValue’ does not adopt it.”

1 Like

Once the user signs in, how do you get it to go to the main section of the app and get off the login view? Sorry, I’m new to this and I can’t seem to figure it out.

Hi Cory! Scott/@gargoyle asked me to answer this.

This tutorial is set up with the login as the only screen. In your app, you’d probably want it to appear as a modal sheet. I wrote a tutorial about SwiftUI navigation, and there’s a section about showing and dismissing a modal. Have a look?

I am curious as to why you pass window as environment(\.window, window). As I understand, @Environment is used in cases where it’s needed to automatically update the view state if the environment object changes. In the current use case it doesn’t look to be the case. Why not just pass UIWindow as a constructor parameter to ContentView? It would be easier (no need to create a custom EnvironmentKey, for instance).

@neverwintermoon I suppose in this case you could do that as it’s a simple example. However, in a real app you’re probably not going to be pushing the sign in window as the very first window you have. It’ll be pushed as part of some type of navigation in the app, based on actions taken. So, in this case, you’d want to have it be in the environment instead of having to pass it around via all the views you might go through to get there.

@gargoyle Can you please help with this when you get a chance? Thank you - much appreciated! :]

@steve46 are you still facing this issue? Can you show your exact code please?