【问题标题】:For iOS 12 or higher display notification (sent via APNS)对于 iOS 12 或更高版本的显示通知(通过 APNS 发送)
【发布时间】:2021-04-22 02:25:34
【问题描述】:

注册远程通知 对于 iOS 12 或更高版本的显示通知(通过 APNS 发送) 我只需要添加下面的代码,对吧?

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

        application.registerForRemoteNotifications()

不需要像 iOS 10 的示例那样的 if-else: https://github.com/firebase/quickstart-ios/blob/365e43642f2cc570df004cb16e098a76cde1e5b1/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55

【问题讨论】:

    标签: ios swift firebase-cloud-messaging apple-push-notifications remote-notifications


    【解决方案1】:

    没错。我试过这段代码,效果很好。

    对于运行 iOS 10 及更高版本的设备,您必须分配 UNUserNotificationCenter 的 delegate 属性和 FIRMessaging 的 delegate 属性。例如,在 iOS 应用中,在应用委托的 applicationWillFinishLaunchingWithOptions: 或 applicationDidFinishLaunchingWithOptions: 方法中分配它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-16
      相关资源
      最近更新 更多