ios - 在 XCode 9 中的 IOS 上使用 Firebase 消息传递

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

每次我尝试运行时,我的应用程序都会使模拟器崩溃,并显示以下消息。

Function boringssl_context_get_peer_sct_list: line 1757 received sct extension length is less than sct data length

我不确定原因,但我希望获得有关以下 3 行正确顺序的反馈:

FirebaseApp.configure()
Messaging.messaging().delegate = self  
// IOS 9 
application.registerForRemoteNotifications() 

// IOS10
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge])
UIApplication.shared.registerForRemoteNotifications()

最佳答案

这是最好的方法。

先请求许可,获得批准后,再注册推送通知

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in

        print("permision granted \(granted)")

        guard granted else { return }

        UNUserNotificationCenter.current().getNotificationSettings { (settings) in
            print("Notification Settings \(settings)")
            guard settings.authorizationStatus == .authorized else { return }

            DispatchQueue.main.async {
                // register
                UIApplication.shared.registerForRemoteNotifications()
            }

        }
    }

关于ios - 在 XCode 9 中的 IOS 上使用 Firebase 消息传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47543485/

相关文章:

ios - 调用了 deinit 但对象仍在内存中

ios - 快速关闭通过引用传递?

ios - [NSObject : AnyObject] ?' does not have a member named ' subscript' error in Xcode 6 beta 6

ios - javapns 是否支持广播推送通知?

ios - Firebase 推送通知

iphone - 无法通过 PHP 代码连接苹果 APN 服务器进行 pusNotification

ios - 将 completionHandler 传递给 NSTimer

ios - 使用 Swift 和 KissXML 创建 XML : example?

ios - 如何在 UITableViewController 中的 UITableView 底部留出空间

ios - 我想要一个 UIView 覆盖整个屏幕甚至导航栏,但显示它的 subview