ASAuthorizationAppleIDProviderCredentialRevoked not in NSNotification.Name

I am using:-
  • SwiftUI

  • Xcode 12 Beta

The code :
Code Block    
let pub = NotificationCenter.default
        .publisher(for: NSNotification.Name.ASAuthorizationAppleIDProviderCredentialRevoked)

The error message :

Type 'NSNotification.Name' has no member 'ASAuthorizationAppleIDProviderCredentialRevoked'


Answered by mash3l777 in 627176022
I just found it it's called
Code Block
ASAuthorizationAppleIDProvider.credentialRevokedNotification
without NSNotification.Name

I test the app and it's working 👏😍

this all code I used:
Code Block
import SwiftUI
import AuthenticationServices
@main
struct AppName: App {
    @ObservedObject var userAuth: UserAuth = UserAuth()
    let pub = NotificationCenter.default
        .publisher(for: ASAuthorizationAppleIDProvider.credentialRevokedNotification)
    @SceneBuilder var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(userAuth)
                .onAppear(perform: {
                    credentialState()
                })
                .onReceive(pub, perform: { _ in
                    credentialState()
                })
        }
    }
    func credentialState() {
        let appleIDProvider = ASAuthorizationAppleIDProvider()
        appleIDProvider.getCredentialState(forUserID: UserDefaults.standard.string(forKey:"userProfileID") ?? "") { (credentialState, error) in
            switch credentialState {
            case .authorized:
                // The Apple ID credential is valid.
                userAuth.login()
            case .revoked, .notFound:
                // The Apple ID credential is either revoked or was not found.
                userAuth.logOut()
                
            default:
                break
            }
        }
    }
}


Try:

Code Block
let pub = NotificationCenter.default
.publisher(for: NSNotification.Name.ASAuthorizationAppleIDProvider.CredentialState.revoked)


The other is for objC
Thanks for respond @Claude31,

same nothing in NSNotification.Name.ASAuth...

Type 'NSNotification.Name' has no member 'ASAuthorizationAppleIDProvider'


Where did you see you could get a notification on revoked ?

Doc states:
https://developer.apple.com/documentation/authenticationservices/asauthorizationappleidprovider

to check if revoked, look at the state like this:
Code Block
let user = authorization.credential.user
provider.getCredentialState(forUserID: user) { state, error in
// Check for error and examine the state.
}

Here 👉Introducing Sign In with Apple WWDC19 12:48
I found this in the documentation credentialRevokedNotification I think it's renamed to this
as apple documentation it's available for iOS 13.0+
but still

Type 'NSNotification.Name' has no member 'credentialRevokedNotification'



@Claude31 is this mention work😅
Accepted Answer
I just found it it's called
Code Block
ASAuthorizationAppleIDProvider.credentialRevokedNotification
without NSNotification.Name

I test the app and it's working 👏😍

this all code I used:
Code Block
import SwiftUI
import AuthenticationServices
@main
struct AppName: App {
    @ObservedObject var userAuth: UserAuth = UserAuth()
    let pub = NotificationCenter.default
        .publisher(for: ASAuthorizationAppleIDProvider.credentialRevokedNotification)
    @SceneBuilder var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(userAuth)
                .onAppear(perform: {
                    credentialState()
                })
                .onReceive(pub, perform: { _ in
                    credentialState()
                })
        }
    }
    func credentialState() {
        let appleIDProvider = ASAuthorizationAppleIDProvider()
        appleIDProvider.getCredentialState(forUserID: UserDefaults.standard.string(forKey:"userProfileID") ?? "") { (credentialState, error) in
            switch credentialState {
            case .authorized:
                // The Apple ID credential is valid.
                userAuth.login()
            case .revoked, .notFound:
                // The Apple ID credential is either revoked or was not found.
                userAuth.logOut()
                
            default:
                break
            }
        }
    }
}


Thanks for feed back. Good you found a way.

I read this: https :// medium.com/ @Ruud_/thanks-for-this-great-tutorial-one-thing-i-noticed-is-that-in-beta-3-this-no-longer-works-3e9320ca7e7a

It is now defined as a class constant of ASAuthorizationAppleIDProvider
Thanks to you 🙏 ❤️ @Claude31
ASAuthorizationAppleIDProviderCredentialRevoked not in NSNotification.Name
 
 
Q