发布于 4年前

Swift 4解决错误:UIApplication.registerForRemoteNotifications() must be called from main thread only

Xcode 9 (iOS 11)注册推送消息报错:

UIApplication.registerForRemoteNotifications() must be called from main thread only

解决方法

Swift 4

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

Objective C

dispatch_async(dispatch_get_main_queue(), ^{
   [[UIApplication sharedApplication] registerForRemoteNotifications];
});
©2020 edoou.com   京ICP备16001874号-3