-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BackgroundFetch.registerHeadlessTask Issues #454
Comments
"headless" = terminated. |
Your logs do not show your app operating in the "headless" (terminated) state. |
OK, thank you - I will adjust and test some more. |
Would be willing to share how I might put my app in the headless state so I
may test?
…On Fri, Jun 23, 2023, 4:40 PM Chris Scott ***@***.***> wrote:
Your logs do not show your app operating in the "headless" (terminated)
state.
—
Reply to this email directly, view it on GitHub
<#454 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AP57MNOME7JQAULR644SQNTXMYEOHANCNFSM6AAAAAAZSA25DY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
.com>
|
If I asked you to terminate the Twitter app (for example), what would you do? |
That's what I thought - realize it was an obvious question, but when I
terminate the app, I don't see anything in the logs indicating this.
…On Sat, Jun 24, 2023, 10:15 PM Chris Scott ***@***.***> wrote:
If I asked you to terminate the Twitter app (for example), what would you
do?
—
Reply to this email directly, view it on GitHub
<#454 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AP57MNPLIHQZCP7PAFROIRDXM6UNRANCNFSM6AAAAAAZSA25DY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
.com>
|
Are you simulating events? |
@christocracy Hi chris, please tell me, on IOS platform when I close the app, when I reopen the app, will the background task event be fired again? Or do I have to start over? |
what background task event are you referring? |
i'm creating a schedule task with name com.transistorsoft.fetchNewData, run every 4 hours, it works fine on IOS if the user doesn't close the app, but I wonder when the user closes the app and reopens it Will my task com.transistorsoft.fetchNewData be reactivated automatically? |
I really don’t know if you have to reschedule it. why don’t you terminate then try simulating the task to see if it runs? |
yes, thank you, i just want to check if it has such a mechanism, i will check it myself |
@christocracy is there any example for headless task ? or can i get some help ? am calling the BackgroundFetch.start() on a specific notification
|
my bad ! i have updated the comment |
BackgroundFetch.configure must not be placed into index.js. It must be place WITHIN your App code. |
i have moved the BackgroundFetch.configure to live cycle method of one of my component and restarted the project . |
Are you simulating events? See the readme to learn how. Are you observing $ adb logcat? |
yes i observing the $ adb logcat ... but i dont see any logs there related to BackgroundFetch. |
Are you simulating events? |
"This" what? I asked you "are you simulating tasks?". Or just sitting there at your desk wasting time under an umbrella waiting for it to rain? |
i dont know what do you mean by "simulating tasks" . But i am following the steps mentioned here and the above screenshot is from the |
Go read the readme and learn how to simulate events.. You don't test this plug-in by staring quietly at your logs waiting for something to happen. |
Read api docs enableHeadless |
Yea, fine, and did you Read the api docs about it?! There's far more involved than just setting it |
This issue is stale because it has been open for 30 days with no activity. |
This issue was closed because it has been inactive for 14 days since being marked as stale. |
For my React Native Application, I am attempting to use the BackgroundFetch.registerHeadlessTask capability. I setup my code per the example, and while the callback for BackgroundFetch.configure fires during my testing, the Headless Task never does.
Your Environment
react-native -v
): 0.71.3Expected Behavior
When my application is in the background or terminated, the method passed to BackgroundFetch.registerHeadlessTask should run.
Actual Behavior
When my application is in the background or terminated, the method passed to BackgroundFetch.registerHeadlessTask never fires.
Steps to Reproduce
App.tsx (snippet)
`const initBackgroundFetch = async () => {
const status: number = await BackgroundFetch.configure({
minimumFetchInterval: 15, // <-- minutes (15 is minimum allowed)
stopOnTerminate: false,
enableHeadless: true,
//startOnBoot: true,
// Android options
forceAlarmManager: false, // <-- Set true to bypass JobScheduler.
requiredNetworkType: BackgroundFetch.NETWORK_TYPE_NONE, // Default
requiresCharging: false, // Default
requiresDeviceIdle: false, // Default
requiresBatteryNotLow: false, // Default
requiresStorageNotLow: false, // Default
}, async (taskId:string) => {
console.log('[BackgroundFetch] taskId', taskId);
BackgroundFetch.finish(taskId);
}, (taskId:string) => {
// Oh No! Our task took too long to complete and the OS has signalled
// that this task must be finished immediately.
console.log('[Fetch] TIMEOUT taskId:', taskId);
BackgroundFetch.finish(taskId);
})};
const App = () => {
const appId = RealmInfo.appId;
const realmApp = createRealmApp(appId);
Realm.App.Sync.setLogLevel(realmApp, 'error');
Realm.App.Sync.setLogger(realmApp, console.log);
useEffect(() => {
initBackgroundFetch();
}, []);`
index.js (snippet)
`messaging().setBackgroundMessageHandler(onMessageReceived);
AppRegistry.registerComponent(appName, () => App);
const onCheckForExpiredLists = async (event) => {
const taskId = event.taskId;
const isTimeout = event.timeout;
if (isTimeout) {
console.log('[BackgroundFetch] Headless TIMEOUT:', taskId);
BackgroundFetch.finish(taskId);
return;
}
console.log('[BackgroundFetch HeadlessTask] start: ', taskId);
BackgroundFetch.finish(taskId);
};`
BackgroundFetch.registerHeadlessTask(onCheckForExpiredLists);
Context
I am attempting to have a notification (notifee) be displayed once a day, depending on condition
Debug logs
06-23 15:36:21.178 2442 2442 D TSBackgroundFetch: ☯ onCreate
06-23 15:36:21.178 2442 2442 D TSBackgroundFetch: ☯️ onStart
06-23 15:36:21.178 2442 2442 D TSBackgroundFetch: ☯️ onResume
06-23 15:36:24.967 2442 2442 D TSBackgroundFetch: ☯️ onPause
06-23 15:36:24.968 2442 2442 D TSBackgroundFetch: ☯️ onStop
06-23 15:37:11.955 5492 5492 D TSBackgroundFetch: ☯️ onCreate
06-23 15:37:11.956 5492 5492 D TSBackgroundFetch: ☯️ onStart
06-23 15:37:11.956 5492 5492 D TSBackgroundFetch: ☯️ onResume
06-23 15:37:11.956 5492 5597 D TSBackgroundFetch: - configure
06-23 15:37:11.956 5492 5597 D TSBackgroundFetch: - start
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: - registerTask: react-native-background-fetch (jobId: 999)
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: {
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "taskId": "react-native-background-fetch",
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "isFetchTask": true,
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "minimumFetchInterval": 15,
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "stopOnTerminate": false,
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "requiredNetworkType": 0,
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "requiresBatteryNotLow": false,
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "requiresCharging": false,
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "requiresDeviceIdle": false,
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "requiresStorageNotLow": false,
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "startOnBoot": false,
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "jobService": "com.transistorsoft.rnbackgroundfetch.HeadlessTask",
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "forceAlarmManager": false,
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "periodic": true,
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: "delay": -1
06-23 15:37:11.961 5492 5597 D TSBackgroundFetch: }
06-23 15:37:19.431 5492 5492 D TSBackgroundFetch: ☯️ onPause
06-23 15:37:19.432 5492 5492 D TSBackgroundFetch: ☯️ onStop
06-23 15:39:01.638 5492 5492 D TSBackgroundFetch: ☯️ onStart
06-23 15:39:01.650 5492 5492 D TSBackgroundFetch: ☯️ onResume
06-23 15:39:51.911 5492 5492 D TSBackgroundFetch: ☯️ onPause
06-23 15:39:51.911 5492 5492 D TSBackgroundFetch: ☯️ onStop
06-23 15:55:41.006 5492 5492 D TSBackgroundFetch: ☯️ onStart
06-23 15:55:41.028 5492 5492 D TSBackgroundFetch: ☯️ onResume
06-23 15:55:41.131 5492 5492 D TSBackgroundFetch: - Background Fetch event received: react-native-background-fetch
06-23 15:55:41.243 5492 5597 D TSBackgroundFetch: - finish: react-native-background-fetch
06-23 15:55:41.243 5492 5597 D TSBackgroundFetch: - jobFinished
06-23 15:55:44.408 5492 5492 D TSBackgroundFetch: ☯️ onPause
06-23 15:55:44.408 5492 5492 D TSBackgroundFetch: ☯️ onStop
The text was updated successfully, but these errors were encountered: