如何解决升级到 Xcode 12.5 后在构建时收到错误,关于注册通知 (Swift)
升级到 Xcode 12.5 后,我的项目无法构建,我的 AppDelegate 出现错误。我可以在升级前确认没有问题,而且我无法在任何地方找到解决此问题的文档。提前致谢!
AppDelegate 代码:
import UIKit
import Firebase
import IQKeyboardManagerSwift
import FirebaseMessaging
@main
class AppDelegate: UIResponder,UIApplicationDelegate {
let gcmMessageIDKey = "gcm.message_id"
func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
IQKeyboardManager.shared.enable = true
Messaging.messaging().delegate = self
if #available(iOS 10.0,*) {
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationoptions = [.alert,.badge,.sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,completionHandler: {_,_ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert,.sound],categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
func application(_ application: UIApplication,didReceiveRemoteNotification userInfo: [AnyHashable: Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
return true
}
}
错误:
1)
application.registerUserNotificationSettings(settings)
“'(UIApplication,[AnyHashable : Any],@escaping (UIBackgroundFetchResult) -> Void) -> ()' 类型的值没有成员 'registerUserNotificationSettings'”
2)
application.registerForRemoteNotifications()
“'(UIApplication,@escaping (UIBackgroundFetchResult) -> Void) -> ()' 类型的值没有成员 'registerForRemoteNotifications'”
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。