Xcode 9 (iOS 11) 在注册推送(远程)通知时向我显示错误/警告。
这里是错误信息
这是我试过的代码:
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
if error == nil{
UIApplication.shared.registerForRemoteNotifications()
}
}
错误/警告线:
UIApplication.shared.registerForRemoteNotifications()
如何解决?
最佳答案
在 swift4
你可以解决这个问题
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
希望这会有所帮助...
关于ios - UIApplication.registerForRemoteNotifications() 只能从主线程调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44391367/