gpt4 book ai didi

ios - FCM 在 iPhone 8 前台模式下无法接收

转载 作者:行者123 更新时间:2023-11-30 11:42:39 25 4
gpt4 key购买 nike

FCM 在前台和后台条件下都能正确接收 iOS 10 设备,但在 iPhone 8 (iOS 11.2) 情况下,FCM 在后台模式下接收。 Appdelegate 包含

@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {

// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo

// With swizzling disabled you must let Messaging know about the message, for Analytics
Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
if let messageID = userInfo[messageKey] {
print("Message ID: \(messageID)")
}

// Print full message.
print("fcm-->\(userInfo)")

// Change this to your preferred presentation option


if UIApplication.shared.applicationState == .active { // In iOS 10 if app is in foreground do nothing.
completionHandler([])
}



NotificationCenter.default.post(name: Notification.Name(rawValue: messageKey), object: nil,userInfo: userInfo)
completionHandler([])
}

func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Print message ID.
if let messageID = userInfo[messageKey] {
print("Message ID: \(messageID)")
}

// Print full message.
print("fcm-->1\(userInfo)")
NotificationCenter.default.post(name: Notification.Name(rawValue: messageKey), object: nil,userInfo: userInfo)
completionHandler()
}
}
// [END ios_10_message_handling]

extension AppDelegate : MessagingDelegate {
// [START refresh_token]
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")

updateGCMIdInServer(fcmToken)

}

func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Received data message 10 +: \(remoteMessage)")
NotificationCenter.default.post(name: NSNotification.Name(rawValue: messageKey), object: nil, userInfo: remoteMessage.appData)
}

}

但是没有到达通知观察者功能。帮助我将数据从 appdelegate 传递到特定的 View Controller

最佳答案

这可能对你有帮助-

@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {

// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
//From here we will navigate to other screens:-


print("User Info : \(userInfo)")

// Change this to your preferred presentation option
//completionHandler([])
completionHandler([.alert,.sound])
}

关于ios - FCM 在 iPhone 8 前台模式下无法接收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49170158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com