File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,9 +43,9 @@ export const registerForPushNotificationsAsync = async () => {
4343
4444 console . log ( "Expo Push Token:" , token ) ;
4545
46+ // Save the token to the server
4647 if ( token ) {
47- // This function seems to be missing from your provided file, assuming it exists elsewhere
48- // await savePushToken(token);
48+ await savePushToken ( token ) ;
4949 }
5050
5151 return token ;
@@ -129,8 +129,28 @@ export const handleBackgroundNotifications = () => {
129129} ;
130130
131131export const savePushToken = async ( token : string ) : Promise < void > => {
132- // Implementation from your file
133- // ...
132+ try {
133+ const response = await fetch (
134+ "https://new.codebuilder.org/api/notifications/subscribe" ,
135+ {
136+ method : "POST" ,
137+ headers : { "Content-Type" : "application/json" } ,
138+ body : JSON . stringify ( {
139+ endpoint : "https://fcm.googleapis.com/fcm/send" ,
140+ keys : { token } ,
141+ type : "fcm" ,
142+ } ) ,
143+ }
144+ ) ;
145+
146+ if ( ! response . ok ) {
147+ throw new Error ( `Error saving token: ${ response . statusText } ` ) ;
148+ }
149+
150+ console . log ( "Push token saved to server successfully." ) ;
151+ } catch ( error ) {
152+ console . error ( "Error saving push token to server:" , error ) ;
153+ }
134154} ;
135155
136156// Example function to trigger a local notification
You can’t perform that action at this time.
0 commit comments