@@ -6,24 +6,25 @@ const BACKGROUND_FETCH_TASK = "background-fetch-task";
6
6
// Define the task
7
7
TaskManager . defineTask ( BACKGROUND_FETCH_TASK , async ( ) => {
8
8
try {
9
+ console . log ( "Background fetch task started" ) ;
9
10
// Perform your API request
10
- const response = await fetch ( "https://api.example.com/data " ) ;
11
+ const response = await fetch ( "https://new.codebuilder.org/api/posts " ) ;
11
12
const data = await response . json ( ) ;
12
13
13
14
// Handle the fetched data
14
15
console . log ( "Fetched data:" , data ) ;
15
16
16
- return BackgroundFetch . Result . NewData ; // Task succeeded
17
+ return BackgroundFetch . BackgroundFetchResult . NewData ; // Task succeeded
17
18
} catch ( error ) {
18
19
console . error ( "Background fetch failed:" , error ) ;
19
- return BackgroundFetch . Result . Failed ; // Task failed
20
+ return BackgroundFetch . BackgroundFetchResult . Failed ; // Task failed
20
21
}
21
22
} ) ;
22
23
23
24
// Register the task
24
- async function registerBackgroundFetch ( ) {
25
+ export async function registerBackgroundFetch ( ) {
25
26
const status = await BackgroundFetch . getStatusAsync ( ) ;
26
- if ( status === BackgroundFetch . Status . Available ) {
27
+ if ( status === BackgroundFetch . BackgroundFetchStatus . Available ) {
27
28
await BackgroundFetch . registerTaskAsync ( BACKGROUND_FETCH_TASK , {
28
29
minimumInterval : 60 , // Fetch interval in seconds (not guaranteed to be exact)
29
30
stopOnTerminate : false , // Continue task when app is closed
@@ -34,5 +35,3 @@ async function registerBackgroundFetch() {
34
35
console . error ( "Background fetch is not available" ) ;
35
36
}
36
37
}
37
-
38
- registerBackgroundFetch ( ) ;
0 commit comments