0

I am trying to send a notification when a user re-signs in with Apple.

I have three parts:

  1. Extension:
extension Notification.Name {
    static let userSignedIn = NSNotification.Name(rawValue: "userSignedIn")
}
  1. 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
                           }
    
                       }
                }
    
  2. 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!

  • 1
    The syntax related to posting and receiving notification seems to be correct. Had you tried adding debug breakpoints to check whether the post notification statement is getting executed – Anmol Suneja Jan 27 '21 at 05:19
  • Yes! Breakpoints, prints, all that. The print statements appear correctly and the breakpoints as well. It may help to know that no post or listener has worked in my app thus far if that correlates to anything –  Jan 27 '21 at 06:32
  • Hey Brandon. Where did you put your addObserver method? – Farrukh Makhmudov Jan 27 '21 at 08:25
  • I can put it anywhere and it will not work; viewDidLoad, viewDidAppear, my won function, nothing. –  Jan 27 '21 at 20:02

1 Answers1

0

May be! delegate does not set.Hope, Here You get the answer --> didReceiveRemoteNotification not called, iOS 10

Mahbeer
  • 1
  • 1
  • 1