Open shammus672agmailcom opened 7 years ago
Please try running the following command:
$ adb logcat *:S ReactNative:V ReactNativeJS:V BackgroundTask:V
And paste your logs here (if it doesn't provide you enough of a clue to tell what's going on).
Keep in mind that after the app leaves the foreground, you'll have to wait at least 50% of the desired period (so, default is 7m30s) before the task executes.
Hey, I m getting the following error while i m executing the package undefined is not an object (evaluating 'RNBackgroundTask.schedule')
@48memory Then the Android library probably wasn't linked correctly. Make sure these changes were made by the react-native link command: https://github.com/jamesisaac/RNBackgroundTaskExample/commit/718b3d2cfe1fa1a649ddb285be921ad8974dff26
Is there a way to test this without having to wait? Similar to how Xcode provides Debug > Simulate background fetch. I was thinking of calling AppRegistry.startHeadlessTask
when the app goes to background, but no dice.
I am also facing same issue please help me out, I am using this library for background work but not working.... This part seams no response ...(no error but not working )
BackgroundTask.define(async () => { // Fetch some data over the network which we want the user to have an up-to- // date copy of, even if they have no network when using the app this.test().done(); BackgroundTask.finish() }) test = async() =>{ console.log('Hello from a background task11'); // Data persisted to AsyncStorage can later be accessed by the foreground app let s = await AsyncStorage.setItem('done','hello'); //alert(JSON.stringify(s)); }
I think it is a bug and the async task should be await . At the path of react-native-background-task/js/index.android.js. I changed the code define: function(task) { // Register the headless task const fn = async () => { task() } AppRegistry.registerHeadlessTask('BackgroundTask', () => fn) }
to
define: function(task) { // Register the headless task const fn = async () => { await task() } AppRegistry.registerHeadlessTask('BackgroundTask', () => fn) }
In my case, it worked. Hope it helps.
thank you.
On Tue, 26 Jun 2018, 17:46 Kent Huang, notifications@github.com wrote:
I think it is a bug and the async task should be await . At the path of react-native-background-task/js/index.android.js. I changed the code
define: function(task) { // Register the headless task const fn = async () => { task() } AppRegistry.registerHeadlessTask('BackgroundTask', () => fn) }
to
define: function(task) { // Register the headless task const fn = async () => { await task() } AppRegistry.registerHeadlessTask('BackgroundTask', () => fn) }
In my case, it worked. Hope it helps.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jamesisaac/react-native-background-task/issues/8#issuecomment-400286013, or mute the thread https://github.com/notifications/unsubscribe-auth/AL2zR0yley5hCFzoikUDklj7M43AmeDDks5uAiYBgaJpZM4OzFz3 .
@kent426 I have the same issue and I did what you say to do and it still doesn't working :( Is there any other solution?
@oron11 I am not sure about your specific problem but, as the library described, you have to wait at least like 10 mins after you put your app into background, for the background task getting executed. Maybe u can elaborate on your problem a bit.
I am using this library for background work but not working.... This part seams no response ...(no error but not working )
BackgroundTask.define(async () => { // Fetch some data over the network which we want the user to have an up-to- // date copy of, even if they have no network when using the app const response = await fetch('http://feeds.bbci.co.uk/news/rss.xml') const text = await response.text()
// Data persisted to AsyncStorage can later be accessed by the foreground app await AsyncStorage.setItem('@MyApp:key', text)