UIApplication.registerForRemoteNotifications() 只能从主线程调用 [英] UIApplication.registerForRemoteNotifications() must be called from main thread only

查看:20
本文介绍了UIApplication.registerForRemoteNotifications() 只能从主线程调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 9 (iOS 11) 在注册推送(远程)通知时向我显示错误/警告.

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()

如何解决这个问题?

推荐答案

In swift4

你可以用

DispatchQueue.main.async {
  UIApplication.shared.registerForRemoteNotifications()
}

希望这会有所帮助...

Hope this will help...

这篇关于UIApplication.registerForRemoteNotifications() 只能从主线程调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆