Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ask for expo token and save to firebase

registerForPushNotifications = async () =>{//Get the current users id So you can post the token to the user in your databaseconst  currentUser = firebase.auth().currentUser.uidconst { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);let finalStatus = existingStatus;// only ask if permissions have not already been determined, because// iOS won't necessarily prompt the user a second time.if (existingStatus !== 'granted') {// Android remote notification permissions are granted during the app// install, so this will only ask on iOSconst { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);finalStatus = status;}// Stop here if the user did not grant permissionsif (finalStatus !== 'granted') {return;}// Get the token that uniquely identifies this devicetry{let token = await Notifications.getExpoPushTokenAsync();// POST the token to your backend server from where you can retrieve it to send push notifications.var updates = {}updates['/expoToken'] = tokenfirebase.database().ref('users').child(currentUser).update(updates)}catch(error){console.log(error)}}
Comment

PREVIOUS NEXT
Code Example
Javascript :: flysystem-aws 
Javascript :: postDataToFirebase 
Javascript :: js show element 
Javascript :: mdn .includes 
Javascript :: generate string from regex javascript 
Javascript :: JS function typeof 
Javascript :: javscript randomly generate 89digit number 
Javascript :: javascript prototype example 
Javascript :: file input only allow json 
Javascript :: how to check invalid control angular formcontrol name 
Javascript :: javascript tousand seperator 
Javascript :: class constructor syntax 
Javascript :: console.log object functions js 
Javascript :: leaflet geojson style stroke width 
Javascript :: gsheet formula get last item in column 
Javascript :: simbu react1 
Javascript :: react hook form submit outside form 
Javascript :: input as html in console 
Javascript :: leaflet flyto 
Javascript :: javascript append classname 
Javascript :: node is not recognized as internal command 
Javascript :: register service worker 
Javascript :: react native test redux 
Javascript :: the rest operator javascript 
Javascript :: node express 
Javascript :: includes in javascript 
Javascript :: creating room in ws nodejs 
Javascript :: how to make html with jquery 
Javascript :: input tag data fetch html javascript 
Javascript :: react state not updating immediately 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =