Wednesday, October 28, 2026
HomeiOS Developmentswift - I am unable to get a FCM click on motion...

swift – I am unable to get a FCM click on motion to work on IOS PWA

[ad_1]

The notifications clicked work positive on each android (put in PWA) and chrome however in ios, I have never had success, For the time being we set the “class” parameter within the payload and the extra actions on the notifications however I’ve not been in a position to carry out a clicked when the notification is clicked.
Is there a technique to ship actionable notifications to iOS gadgets?

Pattern JSON of message payload:

{
    "to": "cadyI6R8vE27vTOfjE157N:APA91bFIEkJqcHzHex9qOOB3eDGWnKg8Fv74iTgDcJDsUVha81hdtphy1fnPDa7rFlRcK48L8vJkthzOp3NyEd_cvSbOcJ4eI335K2N9I-E8ZfA85_2_OnP02OO8vfGv0Gxzz2ACtfSF",
    "collapse_key":"type_a",
    "notification":{
        "title":"Le Soir du2019Algu00e9rie",
        "physique":"Justice : Le procu00e8s de Chakib Khelil pru00e9vu aujourdu2019hui",
        "icon":"/pictures/favicon.png",
        "click_action":"https://www.lesoirdalgerie.com/actualites/les-graves-accusations-de-benbahmed-80545",
        "sound": "default"
    },
    "apns":{
        "payload":{
            "aps":{

                "class":"GENERAL"
            }
        }
    }
}

Right here is my AppDelegatecode :

import UIKit
import FirebaseCore
import FirebaseMessaging


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window : UIWindow?

    func utility(_ utility: UIApplication,
                       didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        // TODO: if we're utilizing Firebase, uncomment this
        FirebaseApp.configure()

        // [START set_messaging_delegate]
        Messaging.messaging().delegate = self
        // [END set_messaging_delegate]
        // Register for distant notifications. This exhibits a permission dialog on first run, to
        // present the dialog at a extra acceptable time transfer this registration accordingly.
        // [START register_for_notifications]
   
        UNUserNotificationCenter.present().delegate = self

        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.present().requestAuthorization(
            choices: authOptions,
            completionHandler: {_, _ in })


        utility.registerForRemoteNotifications()
        
        Messaging.messaging().token { token, error in
          if let error = error {
            print("Error fetching FCM registration token: (error)")
          } else if let token = token {
            print("FCM registration token: (token)")
          }
        }
        
        let generalCategory = UNNotificationCategory(identifier: "GENERAL",
                                                     actions: [],
                                                     intentIdentifiers: [],
                                                     choices: .customDismissAction)
         
        // Register the class.
        let heart = UNUserNotificationCenter.present()
        heart.setNotificationCategories([generalCategory])
        
        Messaging.messaging().subscribe(toTopic: "allDevices") { error in
          print("Subscribed to climate subject")
        }


        // [END register_for_notifications]
        return true
      }

      // [START receive_message]
      func utility(_ utility: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
        // In case you are receiving a notification message whereas your app is within the background,
        // this callback won't be fired until the consumer faucets on the notification launching the appliance.
        // TODO: Deal with information of notification
        // With swizzling disabled you should let Messaging know in regards to the message, for Analytics
        // Messaging.messaging().appDidReceiveMessage(userInfo)
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
          print("Message ID 1: (messageID)")
        }

        // Print full message.
        print("push userInfo 1:", userInfo)
        print("TAB")
        sendPushToWebView(userInfo: userInfo)
      }

      func utility(_ utility: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                       fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // In case you are receiving a notification message whereas your app is within the background,
        // this callback won't be fired until the consumer faucets on the notification launching the appliance.
        // TODO: Deal with information of notification
        // With swizzling disabled you should let Messaging know in regards to the message, for Analytics
        // Messaging.messaging().appDidReceiveMessage(userInfo)
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
          print("Message ID 2: (messageID)")
        }

        // Print full message. **
        print("push userInfo 2:", userInfo)
        print("TAB")
        sendPushToWebView(userInfo: userInfo)

        completionHandler(UIBackgroundFetchResult.newData)
      }

      // [END receive_message]
      func utility(_ utility: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        print("Unable to register for distant notifications: (error.localizedDescription)")
      }

      // This perform is added right here just for debugging functions, and could be eliminated if swizzling is enabled.
      // If swizzling is disabled then this perform should be applied in order that the APNs token could be paired to
      // the FCM registration token.
//      func utility(_ utility: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Information) {
//        print("APNs token retrieved: (deviceToken)")
//
//        // With swizzling disabled you should set the APNs token right here.
//        // Messaging.messaging().apnsToken = deviceToken
//      }
    }

    // [START ios_10_message_handling]
    extension AppDelegate : UNUserNotificationCenterDelegate {

      func userNotificationCenter(_ heart: UNUserNotificationCenter,
                                  willPresent notification: UNNotification,
        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        let userInfo = notification.request.content material.userInfo

        // With swizzling disabled you should let Messaging know in regards to the message, for Analytics
        // Messaging.messaging().appDidReceiveMessage(userInfo)
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
          print("Message ID: 3 (messageID)")
        }

        // Print full message.
        print("push userInfo 3:", userInfo)
          print("ghiii");
          var json = "";
          do {
              let jsonData = strive JSONSerialization.information(withJSONObject: userInfo)
              json = String(information: jsonData, encoding: .utf8)!
              print(json);
              let t = userInfo["aps"] as? [String: Any];
              if let h = t?["category"] as! String? {
                  print(h);
                  if let url = URL(string: h) {
                      UIApplication.shared.open(url)
                  }
              }

          } catch {
              print("ERROR: userInfo parsing downside")
          }
        sendPushToWebView(userInfo: userInfo)

        // Change this to your most popular presentation choice
        completionHandler([[.alert, .sound]])
      }

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

        // With swizzling disabled you should let Messaging know in regards to the message, for Analytics
        // Messaging.messaging().appDidReceiveMessage(userInfo)
        // Print full message.
        print("push userInfo 4:", userInfo)
        sendPushToWebView(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: (String(describing: fcmToken))")
        
        let dataDict:[String: String] = ["token": fcmToken ?? ""]
        NotificationCenter.default.publish(identify: Notification.Title("FCMToken"), object: nil, userInfo: dataDict)
        // TODO: If needed ship token to utility server.
        // Word: This callback is fired at every app startup and every time a brand new token is generated.
      }
      // [END refresh_token]
    }

Any assist can be significantly appreciated since I’ve not discovered a single factor that may assist me perceive this.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments