Push Notifications reply button doesn't work after while

Backendless Version (6.4.3 )

Client SDK (Swift)

Application ID (B807D7C4-910B-5241-FF0A-E447F802D100)

Hello guys.
I created a push notifications with a custom reply button. It works fine when the app is opened. But when I put the app in background, and receive a push notification, and tap the button to reply, the push notification is not sending/replying.

When user taps the reply button on the push notifications, the expected behavior is: replies the push notifications with the string: “OK”.

For me, the app looks like not connected to Backendless, but it is. Why is this happening only when the app goes to background? Remember, if the app is opened the reply button works fine.

Thanks

Hello @wilson-filho,

Could you please provide more info of how do you handle the button tap? What handler do you use?
I’ve just check and this method works fine to handle button taps for both foreground and background states:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)

Documentation link

Regards,
Olha

Hi Olha. Yes, I am doing it.
Look at my code inside the method:


func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

        let publishOptions = PublishOptions()
        publishOptions.headers = ["ios-alert-title": name,
                                  "ios-alert": message,
                                  "ios-badge": 0,
                                  "ios-sound": "default",
                                  "ios-category":"ReplyWithOKCategory",
                                  "senderDeviceId":"\(senderId)",
                                  "senderName":"\(name)",
                                  "senderPhoneNumber":"\(senderPhoneNumber)",
                                  "recipientDeviceId":"\(deviceId)",
                                  "recipientName":"\(recipientName)",
                                  "recipientPhoneNumber":"\(recipientPhoneNumber)"
        ]

        let deliveryOptions = DeliveryOptions()
        deliveryOptions.pushSinglecast = [deviceId]

        Backendless.shared.messaging.publish(channelName: "default", message: message, publishOptions: publishOptions, deliveryOptions: deliveryOptions, responseHandler: { messageStatus in
            print("xxxxxxx Message status: \(messageStatus)")
            
            completion(.success(messageStatus))
        }, errorHandler: { fault in
            print("xxxxxxx Error: \(fault.message ?? "")")
            completion(.failure(fault))
        })

}

the method Backendless.shared.messaging.publish is being calling, but nothing happens.

I’ve just checked your code and everything works fine. The only thing I’ve changed is manually entered the recipient deviceId. Please make sure the deviceId value is correct.

Regards,
Olha

Hi Olha. You didn’t understand. The reply button works when the app is in foreground. But it doesn’t work when the app is in background. My question is why isn’t it work in background?

Thanks

Hello,

Unfortunately I cannot guess what exactly went wrong. This is not a Backendless issue, because you can receive push notifications.
However, I don’t see the completionHandler() call in your didReceive response: UNNotificationResponse method, is it called from here completion(.success(messageStatus)) and completion(.failure(fault)) ?

I can offer you to take a look at this test project, push notifications works fine between several devices, and pressing the custom button sends notifications without any problems from both foreground and background.

PushNotificationsTest.zip (457.7 KB)

(Please, change Bundle Id and Team settings and the deviceId that should receive notification when button pressed).

Regards,
Olha

Hi Olha. I tested with your app example, and the behavior is the same. When the app goes to background and I reply the push notification, nothing happens. I will try here.
Thanks