1

I have a problem to solve with a push message. If I send a push message to Firebase,I will receive it well and I will see the message well.

And when I click on the push message, the userNotificationCenter function in the AppDelegate file is executed and the list of actions in the function is executed.

Can I execute a function without receiving a specific message and displaying a message?

Where I'm currently receiving and processing push messages.

    @available(iOS 10, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        let data = response.notification.request.content.userInfo

        guard
            let push = data[AnyHashable("push")] as? String,
            let getdata = data[AnyHashable("getdata")] as? String,
            let pushdata = data[AnyHashable("pushdata")] as? String
            else {
                print("it's not good data")
                return
        }
        print(push)
        print(getdata)
        print(pushdata)
}

   @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
    {
        completionHandler([.alert, .badge, .sound])
    }

My purpose is to execute the function without showing the push message to the user when sending a specific message (Ex: push = "noShowPush") from the Firebase.

EDit

I was tried "content_available": true but get log 6.10.0 - [Firebase/Messaging][I-FCM002019] FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented

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

        self.window = UIWindow(frame: UIScreen.main.bounds)
        // Override point for customization after application launch.
        //create the notificationCenter
        Messaging.messaging().delegate = self
        FirebaseApp.configure()

        //Register App For Push Notification
        //        self.registerAppForPushNotificaition()
        let center = UNUserNotificationCenter.current()
        let inviteCategory = UNNotificationCategory(identifier: "Notification", actions: [], intentIdentifiers: [], options: UNNotificationCategoryOptions.customDismissAction)
        let categories = NSSet(objects: inviteCategory)

        center.delegate = self
        center.setNotificationCategories(categories as! Set<UNNotificationCategory>)
        DispatchQueue.main.async(execute: {
            UIApplication.shared.registerForRemoteNotifications()
        })
        application.registerForRemoteNotifications()
        self.updateAppViewUI()
        self.window?.makeKeyAndVisible()
        return true
 }
   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) {
        Messaging.messaging().appDidReceiveMessage(userInfo)
        if Auth.auth().canHandleNotification(userInfo) {
            completionHandler(UIBackgroundFetchResult.noData)
            return
        }
        completionHandler(UIBackgroundFetchResult.newData)
    }

I have it already Messaging.messaging().delegate = self.

The logs in the Firebase have warned you to set FirebaseAppDelegateProxyEnabled to No, so I added to the Info.list. enter image description here

and Firebase log changed [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add '[FIRApp configure];' ('FirebaseApp.configure()' in Swift) to your application initialization. Read more:

Are the things I'm revising are going right?

How can I this solution?

hong developer
  • 13,291
  • 4
  • 38
  • 68
  • What you are actually trying to achieve? Your question seems to be unclear. – Lal Krishna Nov 01 '19 at 05:49
  • Is my question hard to understand? My purpose is to execute the function without showing the push message to the user when sending a specific message (Ex: push = "noShowPush") from the Firebase. – hong developer Nov 01 '19 at 05:52
  • @FrankvanPuffelen I think you can solve the problem in firebase. Would you help me with my problem? – hong developer Nov 01 '19 at 17:47

1 Answers1

2

I solved the problem. Here's the order in which I've worked out:

  1. Write when you send a push "content_available": true". And don't include the title and body.
  2. And when I got these error logs, 6.10.0 - [Firebase/Messaging][I-FCM002019] FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented
  3. The logs in the Firebase have warned you to set FirebaseAppDelegateProxyEnabled to No, so I added to the Info.list.

    ㅎㅎ

  4. and changed the order of execution of the function.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
        FirebaseApp.configure() // Let it run first.
        Messaging.messaging().delegate = self
        self.window = UIWindow(frame: UIScreen.main.bounds)
        ...
    
  5. And I installed 'Firebase/Analytics' on the pod. pod 'Firebase/Analytics'

  6. and inherited the MessagingDelegate and implemented the Messaging function.

    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
        print("fcmToken \(fcmToken)")
    }
    
    func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
        Log.Info("remort \(remoteMessage.appData)")
        let userInfo = remoteMessage.appData
    }
    

This configuration allows you to receive push message data into the messaging function when a push message is sent. This is a push message with a 'contentAvailable' value of True and no title and body.

hong developer
  • 13,291
  • 4
  • 38
  • 68