UIApplication.registerForRemoteNotifications() mus

2019-01-08 12:03发布

Xcode 9 (iOS 11) showing me an error/warning while registering for Push (remote) notification.

Here is error message

enter image description here

And here is code, I've tried:

let center  = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
        if error == nil{
              UIApplication.shared.registerForRemoteNotifications()
        }
 }

Error/Warning Line:

UIApplication.shared.registerForRemoteNotifications()

How to resolve this?

7条回答
smile是对你的礼貌
2楼-- · 2019-01-08 12:54

In swift4

You can solve this issue with

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

Hope this will help...

查看更多
登录 后发表回答