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 https://www.raywenderlich.com/4875322-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.
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
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.â
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?