iosreact-nativebackground-fetch

Background fetch, testing problems


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 

Solution

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