https://github.com/nativescript/sample-ios-background-execution
Running Custom Background Tasks with NativeScript
https://github.com/nativescript/sample-ios-background-execution
Last synced: about 1 month ago
JSON representation
Running Custom Background Tasks with NativeScript
- Host: GitHub
- URL: https://github.com/nativescript/sample-ios-background-execution
- Owner: NativeScript
- Created: 2016-08-08T13:23:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-10-24T15:25:33.000Z (about 6 years ago)
- Last Synced: 2024-10-29T15:51:55.478Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 1.66 MB
- Stars: 37
- Watchers: 33
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Running Custom Background Task
For Android sample project please see this repo - https://github.com/NativeScript/sample-android-background-services
A sample project demonstrating how NativeScript application can execute JavaScript code while the app is in background state. On `applicationDidEnterBackground` the app starts a custom [background task](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html). It uses the `NSTimer` API to print a console message on a fixed time interval. To start the task press the `Home` button in order to move the app to the background.
> Since 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](http://stackoverflow.com/questions/28275415/how-long-does-apple-permit-a-background-task-to-run). In some special cases your task is allowed to run longer, but you need to use [UIBackgroundModes](https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH4-SW23) in your `Info.plist` file to specify the intent of your task (which automatically makes it not general-purpose).
# Running the sample
```shell
git clone https://github.com/NativeScript/sample-ios-background-execution.git
cd sample-ios-background-execution
npm install
tns run ios
```