File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,9 @@ export const registerForPushNotificationsAsync = async () => {
43
43
44
44
console . log ( "Expo Push Token:" , token ) ;
45
45
46
+ // Save the token to the server
46
47
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 ) ;
49
49
}
50
50
51
51
return token ;
@@ -129,8 +129,28 @@ export const handleBackgroundNotifications = () => {
129
129
} ;
130
130
131
131
export 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
+ }
134
154
} ;
135
155
136
156
// Example function to trigger a local notification
You can’t perform that action at this time.
0 commit comments