首页 > 解决方案 > 已收到测试飞行中的通知但无法正常工作

问题描述

我正在使用 testflight 测试我的应用程序和 Firebase 消息以发送通知。

发送通知时,具有指定令牌的用户会收到通知,但通过点击通知徽章,应用程序中的相关页面不会出现。就像didReceiveRemoteNotification不叫。

我之前在手机上测试过通知,直接在手机上运行应用程序,效果很好。

我将调试配置文件更改为分发并在 Firebase 中将 APNs 身份验证密钥方法更改为 APNs 证书,但它还不起作用。

这是 AppDelegate。 应用委托

标签: swiftfirebase-cloud-messagingapple-push-notifications

解决方案


我认为您没有在 app delegate 中检查授权didFinishLaunchingWithOptions

UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
    options: authOptions) { (accepted, error) in
        if !accepted{
            CLog.i("Notification not accepted!")
        }
}
UIApplication.shared.registerForRemoteNotifications()

推荐阅读