【发布时间】:2018-01-05 11:11:11
【问题描述】:
我正在我的 didFinishLaunchingWithOptions 方法中像这样在 ios 中注册和启动 firebase。
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
FIRMessaging.messaging().remoteMessageDelegate = self
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
FIRApp.configure()
然后在 AppDelegate 中这样设置回调
func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {
print("fir msg front : \(remoteMessage.appData)")
print(remoteMessage.appData)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
print("fir msg : \(userInfo)")
}
当我从服务器发送消息时,当应用程序不在前台时,它会显示通知,但当应用程序在前台时,我看不到任何通知,也没有回调被调用。我错过了什么吗?
【问题讨论】:
-
您在哪个 iOS 版本中遇到此问题?你实现了 UNUserNotificationCenterDelegate 了吗?
-
我在 10.3.3 中测试,尚未实现 UNUserNotificationCenterDelegate。
标签: ios swift firebase firebase-cloud-messaging