必须仅从主线程调用UIApplication.registerForRemoteNotifications() [英] UIApplication.registerForRemoteNotifications() must be called from main thread only
本文介绍了必须仅从主线程调用UIApplication.registerForRemoteNotifications()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Xcode 9(iOS 11)在注册Push(远程)通知时显示错误/警告。
Xcode 9 (iOS 11) showing me an error/warning while registering for Push (remote) notification.
以下是错误消息
这是代码,我试过了:
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()
UIApplication.shared.registerForRemoteNotifications()
如何解决这个问题?
推荐答案
swift4
你c
DispatchQueue.main.async(execute: {
UIApplication.shared.registerForRemoteNotifications()
})
希望这会有所帮助......
Hope this will help...
这篇关于必须仅从主线程调用UIApplication.registerForRemoteNotifications()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文