如何解决Swift NotificationCenter 未收到邮件
我正在尝试在用户重新登录 Apple 时发送通知。
我分为三个部分:
- 扩展:
extension Notification.Name {
static let userSignedIn = NSNotification.Name(rawValue: "userSignedIn")
}
-
发布通知:
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 } } }
-
接收通知:
NotificationCenter.default.addObserver(self,selector: #selector(profileLaunch(_:)),name: .userSignedIn,object: nil)
我不知道是通知没有发布还是观察者没有被调用。谢谢!
解决方法
可能吧!委托没有设置。希望,在这里你得到答案 --> didReceiveRemoteNotification not called,iOS 10
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。