React Native ios One signal Push notification playerid

627 Views Asked by At

I am trying to get playerid for Onesignal, while doing that it is working strangely.

onIds = async (device) => { 
   console.log("Device info: ", device.userId); 
   let playerid = device.userId; 
   AsyncStorage.setItem('playerid', playerid); 
   //this.setState({device_id: playerid}) 
   alert(playerid); 
}

the above code gives me this error, but in alert I am getting the player id. check the picture attached. enter image description here

Please help me resolve this. Thanks in advance.

1

There are 1 best solutions below

0
On

Like you, I tried a lot, but I could not at least not in the conventional ways, I chose to do the following, saving the ID in the BD directly from the function

async onIds(device) {
    let uri = await AsyncStorage.getItem('uri');
    let token = await AsyncStorage.getItem('token');
    try {
        let formData = new FormData();
        formData.append(
            'PNToken',
            JSON.stringify({
                PushNotificationsID: device.userId
            })
        );
         await fetch(uri, {
            method: 'POST',
            headers: {
                'Content-Type': 'multipart/form-data',
                Authorization: 'Bearer ' + token
            },
            body: formData
        });
    } catch (e) {
        console.warn(e);
    }
}