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 
4
  • Xcode menu > Debug > Simulate Background Fetch Commented Sep 22, 2017 at 7:04
  • @Desdenova That is what I am doing, did you read it ? Commented Sep 22, 2017 at 7:08
  • Appearantly not :) Sorry Commented Sep 22, 2017 at 7:10
  • Please add minimal reproducible example Commented Sep 22, 2017 at 7:11

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

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.

3 Comments

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
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.
Because now you can send logs to some server in place. Depends on your imagination to solve a problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.