Support Topics Documentation Slack YouTube Blog

Get the complete list of device token


(Francesco) #1

Hi guys,
I need to get the complete list of the registered devices for push notification.
I know that there is a rest api to retrieve the device id and, with that code, get the related user.

But is there a method to get the device tokens of the unregistered user? I have a lot of people without account that are registered to the push notification channel. How can retrieve all those token?


(Olga Danylova) #2

Hello Francesco,

You can retrieve device tokens using data retrieval with the DeviceRegistration table.

Here is the Swift example for the default channel.

Dictionary/Map approach

    let queryBuilder = DataQueryBuilder()!
            queryBuilder.setWhereClause("channelName = 'default'")
            
            let deviceStore = Backendless.sharedInstance()?.data.ofTable("DeviceRegistration")
            deviceStore?.find(queryBuilder, response: { deviceRegistrations in
                print("Devices: ")
                for deviceRegistration in deviceRegistrations as! [[String : Any]] {
                    print(deviceRegistration["deviceToken"]!)
                }
            }, error: { fault in
                print("Error: \(fault!)")
            })

Class approach

let deviceStore = Backendless.sharedInstance()?.data.of(DeviceRegistration.ofClass())
        deviceStore?.find(queryBuilder, response: { deviceRegistrations in
            print("Devices: ")
            for deviceRegistration in deviceRegistrations as! [DeviceRegistration] {
                print(deviceRegistration.deviceToken!)
            }
        }, error: { fault in
            print("Error: \(fault!)")
        })

Regards,
Olga


(Francesco) #3

Thank you for your reply but I’m using the old version of backendless…is it possible to retrieve tokens with the old version?


(Olga Danylova) #4

No, it is not possible.