react-native-background-task icon indicating copy to clipboard operation
react-native-background-task copied to clipboard

Task defined did not run in IOS

Open CharltonC opened this issue 8 years ago • 15 comments

I used the Simple example provided in your readme and I can't see the msg logged in the Chrome React Native Debugger. Not sure what I missed.

Packages Versions:

  • Xcode: 8.2.1
  • NPM: 3.10.10 "react": "16.0.0-alpha.12", "react-native": "0.45.1", "react-native-background-fetch": "^2.0.8", "react-native-background-task": "^0.2.0"

CharltonC avatar Jul 27 '17 02:07 CharltonC

Try using the "Simulate Background Fetch" feature of Xcode, documented here: https://developer.apple.com/library/content/documentation/IDEs/Conceptual/iOS_Simulator_Guide/TestingontheiOSSimulator/TestingontheiOSSimulator.html#//apple_ref/doc/uid/TP40012848-CH4-SW5

Were you using a simulator or device? From what I understand the Simulator doesn't run background code by itself. If you were using a real device then it probably should have run after ~15 mins.

jamesisaac avatar Jul 27 '17 11:07 jamesisaac

It was tested on device.

CharltonC avatar Aug 01 '17 03:08 CharltonC

Can you try out with Simulate Background Fetch and just confirm that works first?

If it does, it's probably a sign that the task is set up properly, but Apple's algorithm is choosing not to run it (which sadly there isn't much we can do about).

Did you force close the app, rather than just leaving it running in the background? That's one which will unfortunately stop the background task occurring (until the user opens the app again), under Apple's policies.

jamesisaac avatar Aug 01 '17 09:08 jamesisaac

The app was not closed. Home button is pressed to leave the App in Bg. I tried out the Simulate Bg Fetch in Simulator and it didn't work either. I think it may be easier if you can include a repo of working example which I can clone to have a look, since you already tested and confirmed that it is working?

I also happen to find one interesting quote when reading Nativescript.

From NativeScript Docs for "smple-ios-background-execution":

iOS doesn't allow a general-purpose background task to run forever, such a task will be suspended by the operating system after approximately 3 minutes. In some special cases your task is allowed to run longer, but you need to use UIBackgroundModes in your Info.plist file to specify the intent of your task (which automatically makes it not general-purpose).

https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH4-SW23

CharltonC avatar Aug 02 '17 02:08 CharltonC

the simple fetch example is not working in Android....i have follow all the steps but it is not working.Please provide a simple working example of this

shammus672agmailcom avatar Aug 07 '17 07:08 shammus672agmailcom

Sure, I'll tidy up and include the example project I was using shortly, which worked on both Android and iOS.

Once that is up, @shammus672agmailcom , could you please open a new issue if you are still experiencing problems, as the debugging process is completely different for Android vs iOS.

jamesisaac avatar Aug 08 '17 12:08 jamesisaac

I've created an example project here: https://github.com/jamesisaac/RNBackgroundTaskExample which includes step by step commits so you can see each part of the setup process.

I haven't tested this exact release of the project on iOS yet (I normally use Windows/Android so a bit of a hassle to get the environment set up), but this is almost identical to the initial code I was using to test the library across both platforms. Maybe you'll spot something you've done differently. I will test it myself shortly on iOS just to confirm everything is still working.

jamesisaac avatar Aug 10 '17 10:08 jamesisaac

I am facing similar problem, I was also not able to run background task in my iphone background As per documents I have define task but it does not print "Hello from a background task" on console

Below is my version, let me know if it is related to version or device

Node Version: 6.0.0 Npm Version: 3.8.6 Xcode Version: 8.0 react Version: "16.0.0-alpha.12", react-native Version : "0.48.3", react-native-background-fetch Version : "^2.0.8", react-native-background-task Version: "^0.2.1", Device : iphone 5c Device OS: 9.3.3

binitpatel avatar Sep 22 '17 08:09 binitpatel

Same here

antonsivogrivov avatar Nov 20 '17 12:11 antonsivogrivov

Here's one more thing to try, make sure Background Fetch is enabled for the project:

To support this mode, enable the Background fetch option from the Background modes section of the Capabilities tab in your Xcode project. (You can also enable this support by including the UIBackgroundModes key with the fetch value in your app’s Info.plist file.)

jamesisaac avatar Nov 20 '17 13:11 jamesisaac

Same issue

mirkods avatar Jan 03 '18 09:01 mirkods

Hi all, I have a similar issue. My code is working fine on android as background task but ios it is not working.

I checked all permissions and when called statusAsync() is available. All ios background services are enabled and background updates too.

It is not working in debugging and release mode. Another behavior is about background fetch. When I force "Simulate Background Fetch" the Xcode breaks in a line with message SIGSTOP but if I force "continue" event, all will works.

Can you help me?

arieldll avatar May 18 '18 11:05 arieldll

This worked beautifully on the iOS Simulator with Debug > Background Fetch but couldn't get it to work on a real iOS device. Would love to have this working on the device as well, as it really helped achieve the background process work on the Simulator without many hitches.

askarhu avatar Aug 16 '18 21:08 askarhu

This worked beautifully on the iOS Simulator with Debug > Background Fetch but couldn't get it to work on a real iOS device. Would love to have this working on the device as well, as it really helped achieve the background process work on the Simulator without many hitches.

@askarhu Did it work for you? I am stuck in similar situation, it worked well with 'Simulate Background Fetch' on xCode but it doesn't seem to work with production build, I even waited for 2 days, but background fetch was never triggered.

crup avatar Feb 04 '19 12:02 crup

Having the same issue: it is working with the 'Simulate Background Fetch' but when built as release build it was not executed a single time during the past 12 hours...

Like @binitpatel I am also using an older version of this library (as recommended by react-native-background-task):

"react-native-background-fetch": "^2.0.8",
"react-native-background-task": "^0.2.1",

Could it be related to that? Maybe because the capability Background processing is not set? 🤔

Was somebody here able to solve it somehow?

flogy avatar Mar 09 '21 05:03 flogy