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

用户10002550

如何在 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()

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Firebase更新AppDelegate

如何修复已弃用的“ buttonstyle”

如何修复 JaCoCo reportDir 已弃用

如何在 Firebase 函数中使用 --fix 修复 Lint 问题

如何在 Java 中使用已弃用的导入?

如何使用Urban AirShip(Swift)获取appDelegate

Flutter:如何使用Firebase PhoneNumberAuth修复设备丢失的连接错误

Xcode 问题 AppDelegate 与 Firebase - 'NSPersistentCloudKitContainer'

如何在运行项目时修复Xcode AppDelegate错误?

如何修复'sizeWithFont:constrainedToSize:lineBreakMode:'已弃用:警告

如何修复 UIWebView 已弃用的 Ionic 3

如何在Symfony 4中修复已弃用的用户?

如何修复错误:已弃用:必需参数

将 Firebase 云消息传递与 Django-Push-Notifications 结合使用时,如何使用 TTL 来防止消息积压?

Swift、Firebase - 如果用户已登录,则在 AppDelegate 中显示不同的 ViewController

如何确认AppDelegate的ObservableObject?

如何从Appdelegate显示UIAlertController

如何从appDelegate呈现UIAlertView

如何从 appDelegate 到 viewController

我如何从目标C代码获取Swift AppDelegate的引用

如何重构代码以在主线程上调用AppDelegate?

如何使用Xamarin形式在PCL类中调用Appdelegate函数?

如何使用Swift在Appdelegate中获取当前位置

Firebase.configure()阻止AppDelegate:OpenUrl()的调用

Firebase云消息传递AppDelegate错误

如何修复这个 AndroidANR?

如何修复这个功能?

如何修复这个 ValueError?

如何修复这个循环