2

I have a react-native application which includes react-native-background-task which uses react-native-background-fetch. I configured a job to console.log a simple message when it runs. I understand that the background fetch is not working on simulator, but you can test it by going into Debug -> Simulate background fetch. When I hit this, the app goes to background. I did not get any output. I have enabled background fetch in Info.plis and also the code returns status.available when I check with the library function. How do you actually test this?

Xcode 8.3.3
react-native 0.44.0
react-native-background-fetch 2.0.8 
react-native-background-task 0.2.1



class App extends Component {
componentWillMount() {
  BackgroundTaks.define(() => {
    console.log('==================FETCH==================');
    console.log('task running');
    console.log('====================================');

    BackgroundTaks.finish();
  });
}

componentDidMount() {
  BackgroundTaks.schedule();
}

render() {
  return (
    <Router />
  );
}}

export default App;

I am getting the same breakpoint when I Simulate background fetch using real device

libsystem_kernel.dylib`mach_msg_trap:
    0x186e9721c <+0>: mov    x16, #-0x1f
    0x186e97220 <+4>: svc    #0x80
->  0x186e97224 <+8>: ret 
LW001
  • 2,452
  • 6
  • 27
  • 36
parohy
  • 2,070
  • 2
  • 22
  • 38

2 Answers2

1

Solved. At the end I realized the background fetch checkbox was not checked in the project settings. After checking it does work.

parohy
  • 2,070
  • 2
  • 22
  • 38
0

Since you've mentioned that you've tried writing to storage also - which is not working - my updated answer would be: while you are running background fetch, you can at the same time hit a server on which you can see the logs. That way, you can tell, if the background fetch was successfully working.

I've created a hackable localTestingServer that you can fork and get started immediately.

prabodhprakash
  • 3,825
  • 24
  • 48
  • I edit the question. I tried using storage as well but there was no result after simulating background fetch. I even installed it on the device and let it run for a while but the storage was not updated – parohy Sep 22 '17 at 07:10
  • How does this lead to narrowing down the possible problem, when all I do is run a background task to set a dummy string to storage or print an output? It does not run the task at all and throws the exception I added to the question. – parohy Sep 22 '17 at 07:55
  • Because now you can send logs to some server in place. Depends on your imagination to solve a problem – prabodhprakash Sep 22 '17 at 07:56