I’ve checked the custom object message listener with this code and it works fine for me - I received the published message status and got the object in listener (checked within your app):
let channelName = "E7880B05-C212-4DF3-947F-425D592FFD99"
let channel = Backendless.shared.messaging.subscribe(channelName: channelName)
let _ = channel.addCustomObjectMessageListener(forClass: MessageAndSender.self, responseHandler: { response in
guard let response = response as? MessageAndSender else { return }
print("Custom object: \(response.msgTxt ?? ""), \(response.pubName ?? "")")
}, errorHandler: { fault in
print("Listener Error: \(fault.message ?? "")")
})
DispatchQueue.main.asyncAfter(deadline: .now() + 4, execute: {
let custobj = MessageAndSender()
custobj.threadObjectId = "test"
custobj.msgTxt = "test"
custobj.pubName = "test"
Backendless.shared.messaging.publish(channelName: channelName, message: custobj, responseHandler: { status in
print("Published: \(status.status ?? "")")
}, errorHandler: { fault in
print("Publish Error: \(fault.message ?? "")")
})
})
@objcMembers
class MessageAndSender: NSObject, ObservableObject, Identifiable {
var objectId: String?
///objectId of MsgThread object
var threadObjectId: String?
@Published var msgTxt: String?
@Published var pubName: String?
@Published var pubProfilePicURL: String?
///objectId of senders public profile
var fromObjectId: String?
var created: Date?
}
If it doesn’t work for you anymore, could you please provide an object you’re sending with all its fields?
I have an update for you. We have release the fix for the issue you wrote us about:
PUSH notifications throwing a server error
Please check the fix for the problem on your side if you have the opportunity. Let us know how it works for you now. We will be waiting for the results of your check.
thank you! I can confirm that sending a custom object into a PUSH notification works without error. I can also receive a custom object through the addCustomObjectEventListener successfully. I’ll mark this as resolved. One last question regarding this process:
What is the best way to handle the custom object that is received via the PUSH notification inside the NotificationService? Do I just need to parse the JSON manually or is there a convenience method from the BE SDK that does this?
a custom object as a message is processed by server and returned as a JSON String in the push notification payload.
It’s not a dictionary but string that can include the escaping characters.
At the point we don’t provide an ability to handle custom objects in push notifications, so I can only recommend you to do it on your side.