Swift NotificationCenter 未收到邮件

问题描述

我正在尝试在用户重新登录 Apple 时发送通知

我分为三个部分:

  1. 扩展:
extension Notification.Name {
    static let userSignedIn = NSNotification.Name(rawValue: "userSignedIn")
}
  1. 发布通知

        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. 接收通知

    NotificationCenter.default.addobserver(self,selector: #selector(profileLaunch(_:)),name: .userSignedIn,object: nil)

我不知道是通知没有发布还是观察者没有被调用。谢谢!

解决方法

可能吧!委托没有设置。希望,在这里你得到答案 --> didReceiveRemoteNotification not called,iOS 10