我正在尝试使用 Firebase 在我的应用程序中实现推送通知,但是在按照他们的文档进行操作时,我必须添加以下代码行:
if #available(iOS 10.0, *) {
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions, completionHandler: {_, _ in})
UNUserNotificationCenter.current().delegate = self
FIRMessaging.messaging().remoteMessageDelegate = self
} else {
let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
添加这段代码后,应用程序将无法编译,它会向我抛出一个错误让我知道我
cannot assign value of type
AppDelegate
to typeFirMessagingDelegate
还有我
cannot assign value of type AppDelegate to type UNUserNotificationCenterDelegate.
很自然地,我将 FIRMessagingDelegate
和 UNUserNotificationCenterDelegate
添加到我的应用程序中,但是 FIRMessagingDelegate
不允许应用程序编译说
type AppDelegate does not conform to protocol 'FirMessagingDelegate'.
有什么想法吗?我还没有找到其他人遇到此错误的其他情况,而且在 Google 的文档中,甚至没有添加这两个委托(delegate)。
最佳答案
你走在正确的轨道上,还有一件事是让你的 AppDelegate 类符合“FirMessagingDelegate”协议(protocol),通过在你的 AppDelegate 类的某个地方实现 applicationReceivedRemoteMessage
函数,因为它是此处描述的“FirMessagingDelegate”协议(protocol) Firebase Doc
关于ios - 如何处理 Swift 3 中 UNUserNotificationCenter 和 FIRMessaging w/Firebase 的委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41406170/