Receiving Custom Data (Bool, Int) from Firebase Cloud Messaging

I'm sending a custom FCM message (more than just a title and a body) to my iOS app through curl as follows.

curl -X POST --header "Authorization: key=myServerKey" \
--Header "Content-Type: application/json" \ \
-d @- << EOF
  "to": "my device token",
    "data": {
        "urlFlag": true,
        "category": "Electric",
        "messageId": 1238884523
    "notification": {
        "title": "Test"
        "body": "What do you want?"

And I receive the push message through the userNotificationCenter(_:willPresent:withCompletionHandler:) method in AppDelegate as follows.

import UIKit
import Firebase

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        /* Firebase Cloud Messaging */
        Messaging.messaging().delegate = self
        Messaging.messaging().token { token, error in
            if let error = error {
                print("Error fetching FCM registration token: \(error)")
            } else if let token = token {
                if self.showFirebaseToken {
                    print("Remote FCM registration token: \(token)")
        if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self
            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
                options: authOptions,
                completionHandler: {_, _ in })
        } else {
            let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        return true

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        let userInfo = notification.request.content.userInfo
        if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID)")
        completionHandler([[.alert, .sound]])
        if let aps = userInfo["aps"] as? [String: Any], let alert = aps["alert"] as? [String: Any] {
            if let title = alert["title"] as? String, let body = alert["body"] as? String {
                print("title: \(title) body: \(body)") // good
        if let urlFlag = userInfo["urlFlag"] as? Bool {
            print("Flag: \(urlFlag)") // no good
        if let category = userInfo["category"] as? String {
            print("category: \(category)") // good
        if let messageId = userInfo["messageId"] as? Int {
            print("ID: \(messageId)") // no good

The app does receive the title and the body with no problem. If the custom dataset contains a boolean type, a string type, a number type, the app will only receive the String one only. How can I have my app receive a boolean type and a number type? Thanks.


userInfo returns the following.

[AnyHashable("google.c.fid"): cgthRgMJPEkaidXXhrXuqv, AnyHashable("urlFlag"): true, AnyHashable("messageId"): 1238884523, AnyHashable("aps"): {

    alert =     {

        body = "What do you want?";

        title = Test;


}, AnyHashable(""): 1073343011223, AnyHashable("category"): Electric, AnyHashable("google.c.a.e"): 1, AnyHashable("gcm.message_id"): 1627387811171401]
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum