Message Publish Options : About the Use of setPushSingleCast() function

Hello Backendless,
I was wondering about the Use of SetPushSingleCast() function in Messaging API . Let’s put a Use case in play here. Suppose I have a Channel A with 1000 Registered Device on the Channel named Device 1 , Device 2 , …Device 1000
When I Publish a Message in the Channel , the Message will be Broadcasted to those 1000 Devices.
But, I want to Achieve Same Thing by Using this type of Code :

List<String>recieversList=new ArrayList<String>();
//recieversList is somehow populated with Valid device Id's 

DeliveryOptions dov=new DeliveryOptions();
dov.setPushSingleCast(recieversList);
Backendless.Messaging.Publish((Object)"Message",publishOptions,dov); 

I was just Wondering if the below Code Would allow me to Achieve the same Using “Default” Channel

Regards,
Pujan Paudel

Hi Pujan,

Yes, it would result in the same behavior - the message is delivered to the specific devices identified in the request.

Regards,
Mark

Hi Mark

I have a problem with Android phones using setPushSingleCast send to all the channel to filter could be possible?

func sendNotification(deviceIdList: [String]) {
print("sendNotification INIT: ", deviceIdList )

    let publishOptions = PublishOptions()
        publishOptions.setHeaders(headers:
                                    ["android-ticker-text": "Targett Acceso - Autorizaciones",
                                     "android-content-title": "Autorización Pendiente",
                                     "android-content-text": "Destino: " + self.nameDestino,
                                     "ios-alert": "OtorgarAutorizacion",
                                     "ios-badge": 1,
                                     "ios-sound": "ring.wav",
                                     "metodo": "OtorgarAutorizacion",
                                     "mag_objectId": self.autorizacionObjectId
                                    ])

    let deliveryOptions = DeliveryOptions()
    deliveryOptions.setPushSinglecast(singlecast: deviceIdList)

    Backendless.shared.messaging.publish(channelName: "default",
                                         message: "Destino: " + self.nameDestino,
                                         publishOptions: publishOptions,
                                         deliveryOptions: deliveryOptions,
                                         responseHandler: { messageStatus in
        print("Message status: \(messageStatus)")
        print("Mensaje PUSH enviado")
        
    }, errorHandler: { fault in
        print("Error: \(fault.message ?? "")")
        AlertViewController.sharedInstance.showErrorAlert(fault, self)
    })
}

The Log it’s only this deviceId:

sendNotification INIT: [“abc3d5c9b08b8b0e”]

Thanks, Mario

Solved the problem was not check if deviceIdList become empty!

Thanks, Mario