Swift如何在系统启动之前更改从Firebase(FCM)收到的通知标题和尸体



在系统启动之前,我如何更改收到的firebase通知的标题和正文?

我成功收到了通知,但我需要在节目通知之前修改标题和正文

这是我的AppDelegate

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[gcmMessageIDKey] {
        print("Message ID: (messageID)")
    }
    // Print full message.
    print(userInfo)
    // Change this to your preferred presentation option
    completionHandler([.alert,.sound])
}
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[gcmMessageIDKey] {
        print("Message ID: (messageID)")
    }
    // Print full message.
    print(userInfo)
    completionHandler()
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
    // If you are receiving a notification message while your app is in the background,
    // this callback will not be fired till the user taps on the notification launching the application.
    // TODO: Handle data of notification
    // With swizzling disabled you must let Messaging know about the message, for Analytics
    // Messaging.messaging().appDidReceiveMessage(userInfo)
    // Print message ID.
    if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: (messageID)")
    }
    // Print full message.
    print(userInfo)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    // If you are receiving a notification message while your app is in the background,
    // this callback will not be fired till the user taps on the notification launching the application.
    // TODO: Handle data of notification
    // With swizzling disabled you must let Messaging know about the message, for Analytics
    // Messaging.messaging().appDidReceiveMessage(userInfo)
    // Print message ID.
    if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: (messageID)")
    }
    // Print full message.
    print(userInfo)
    completionHandler(UIBackgroundFetchResult.newData)
}

这看起来类似于这里问的问题:可以在iOS端显示在设备上显示吗?

可以更改推送通知消息?

在通知服务中看起来可能是可能的,但是,您也可以按照您打算写的方式从FCM发送有效载荷。有原因是您无法从服务器修改它吗?

相关内容

  • 没有找到相关文章

最新更新