gpt4 book ai didi

ios - 如何修复 AppDelegate for Firebase Notifications 中使用的已弃用代码?

转载 作者:行者123 更新时间:2023-11-28 14:33:33 25 4
gpt4 key购买 nike

如何在 Swift 4 中使用以下在 iOS 10 中已弃用的代码?此应用程序用于使用 Firebase 发送推送通知。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

let notificationTypes : UIUserNotificationType = [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound]
let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)

application.registerForRemoteNotifications()
application.registerUserNotificationSettings(notificationSettings)


return true
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")

print(userInfo)
}

感谢任何帮助,谢谢。

最佳答案

这是我现在在使用 Firebase 通知的应用程序中执行的操作。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self

let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })

// For iOS 10 data message (sent via FCM)
Messaging.messaging().remoteMessageDelegate = self

} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}

application.registerForRemoteNotifications()

FirebaseApp.configure()

}

关于ios - 如何修复 AppDelegate for Firebase Notifications 中使用的已弃用代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51072332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com