I am trying to send a notification when a user re-signs in with Apple.
I have three parts:
- Extension:
extension Notification.Name { static let userSignedIn = NSNotification.Name(rawValue: "userSignedIn") }
Post Notification:
if let userIdentifier = UserDefaults.standard.object(forKey: "appleSignIn") as? (String) { let authorizationProvider = ASAuthorizationAppleIDProvider() authorizationProvider.getCredentialState(forUserID: userIdentifier) { (state, error) in switch (state) { case .authorized: print("Account Found - Signed In") DispatchQueue.main.async { NotificationCenter.default.post(name: .userSignedIn, object: nil) } break case .revoked: print("No Account Found") fallthrough case .notFound: print("No Account Found") DispatchQueue.main.async { } default: break } } }
Receive notification:
NotificationCenter.default.addObserver(self, selector: #selector(profileLaunch(_:)), name: .userSignedIn, object: nil)
I can't tell whether the notification is not getting posted or the observer is not getting called. Thanks!