'Cannot find type 'ASAuthorizationControllerDelegate' in scope when archiving

macOS Monterrey 12.0.1 (21A559)

Xcode 13.3.1 (13E500a)

iOS app deployment target 10.0

I have been working with this app for a few years now, when the Apple authentication was released, I implemented it in the app, all had been going well but...

I am doing an update, with small fixes and mainly changes of style, I worked on the update, tested in real devices and simulators, then archived and uploaded for test flight for further testing.

Yesterday 11/05/2022, I did some changes I was requested, after the test flight users reported somethings, such things were minor and in no way included the Apple authentication. So I worked on the changes, tested again in simulators and real devices and all was ready for archiving.

I hit archive, so I can upload a new version to test flight and am welcomed with the message:

error: cannot find type 'ASAuthorizationControllerDelegate' in scope
extension ActivityUtils: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: cannot find type 'ASAuthorizationControllerPresentationContextProviding' in scope
extension ActivityUtils: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
                                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: cannot find type 'ASPresentationAnchor' in scope
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
                                                                      ^~~~~~~~~~~~~~~~~~~~
error: cannot find type 'ASAuthorizationController' in scope
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~
error: cannot find type 'ASAuthorizationController' in scope
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
                                         ^~~~~~~~~~~~~~~~~~~~~~~~~
error: cannot find type 'ASAuthorization' in scope
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
                                                                                                                ^~~~~~~~~~~~~~~
error: cannot find type 'ASAuthorizationController' in scope
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
                                         ^~~~~~~~~~~~~~~~~~~~~~~~~
error: cannot find 'ASAuthorizationAppleIDProvider' in scope
    let appleIDProvider = ASAuthorizationAppleIDProvider()
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: cannot find 'ASAuthorizationController' in scope
    let authorizationController = ASAuthorizationController(authorizationRequests: [request])
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~
error: cannot find type 'ASAuthorizationAppleIDCredential' in scope
    if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: cannot find type 'ASAuthorizationError' in scope
    guard let error = error as? ASAuthorizationError else {
                                ^~~~~~~~~~~~~~~~~~~~

I am not sure where to go from here, I cleaned the build folder, I deleted all cache from xcode, restarted xcode, restarted the computer, got frustrated and left it as is, some time later I tried again and the thing works.

My best guess was that maybe during the archive process, Xcode queries some server to download the AuthenticationServices package and maybe it was down, so I forgot about it.

Yesterday I also did some tests on the app that I got from test flight and found a bug, I went to fix it and I was ready to archive again, and then the error again, over and over, this time the waiting did not help, I started searching for answers all over and could not find anyone with the exact same issue, however, from similar issues I followed some advice, to add the following:

#if arch(arm64) || arch(i386) || arch(x86_64)
    //mycode
#endif

around the problem areas, which actually worked, but the question remains, why it has stopped working all of the sudden, does anyone have a clue?

I am also wondering if there is a particular new requirement for AuthenticationServices? I searched for it and as far as I can tell, the only requirement is iOS 13 or greater. Could this also have to do with the Monterrey and Xcode 13 update?

Edit:

I am no longer having the issue, I did some changes which in my opinion should have not changed the result but looks like they had an effect.

All I did was move part of the class to other files as extensions, if this actually fixed the issue (as I am unsure this can't happen again) then there is a limit on how big a file can be, could that be?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source