Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
shridharav authored Jun 24, 2022
1 parent d7c7886 commit a27a3e6
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
# BackgroundTasks
Apple has introduced the [BackgroundTasks](https://developer.apple.com/documentation/backgroundtasks) framework in iOS 13 to allow apps to run tasks in the background state to keep app content up to date.
Register launch handlers for tasks when the app launches and schedule them as required. The system will launch your app in the background and execute the tasks. The system decides the best time to launch your background task, and provides your app up to 30 seconds of background runtime. Complete your work within this time period and ACK, or the system terminates your app.
Register launch handlers for tasks when the app launches and schedule them as required. The system will launch your app in the background and execute the tasks. The system decides the best time to launch your background task, and provides your app up to 30 seconds off background runtime. Complete your work within this time period and ACK, or the system terminates your app.

# BGTasks
[![Swift 5.1](https://img.shields.io/badge/Swift-5.1-orange.svg)](https://swift.org)
[![CocoaPods](https://img.shields.io/cocoapods/v/BGTasks.svg)](https://github.com/PhonePe/BGTasks)

A wrapper over iOS provided **BackgroundTasks** framework to ensure smooth onboarding of usecases and handle all the complex functionalities of **BackgroundTasks** within it.
A wrapper over iOS provided **BackgroundTasks** framework to ensure smooth onboarding of use cases and handle all the complex functionalities of **BackgroundTasks** within it.
Functionalities provided in the framework are:
- Integrate or register a usecase for background sync/refresh with ease.
- Integrate or register a use case for background sync/refresh with ease.
- Handled all complex registration and callbacks mechanisms provided by OS.
- Prioritizing use cases based on:
- Strategy [everyTime, onceInADay, etc] - Currently only one strategy is supported i.e everyTime
- Callbacks are given to usecase based on the threshold or elapsed time-interval from the last sync time.
- In-built analytics support to know how many tasks were scheduled, launched and completed. This also given data on a usecase level.
- Prioritising use cases based on:
- Strategy [everyTime, onceADayAnyTime, every4Hours, every12Hours, every24Hours]
- Callbacks are given to use case based on the threshold or elapsed time-interval from the last sync time.
- In-built analytics support to know how many tasks were scheduled, launched and completed. This also given data on a use case level.

## API usage
#### Framework Initialisation
```swift
import BGTasks

let permittedIdentifiers: [BGTaskSchedulerType: String] = [
.appRefreshTask: "com.app.refresh.task",
.processingTaskWithConnectivityWithExternalPower: "com.processing.task.with.connect.with.power",
.processingTaskWithConnectivityWithoutExternalPower: "com.processing.task.with.connect.no.power",
.processingTaskWithoutConnectivity: "com.processing.task.no.connectivity"
]
let config = BGConfigurationProvider.RegistrationData(permittedIdentifiers: permittedIdentifiers)
BGConfigurationProvider.shared.configure(config: config)
```
All the identifiers must be added into the project's `Info.plist` under `BGTaskSchedulerPermittedIdentifiers` key.

#### Use-case registration
```swift
import BGTasks

let data = BGSyncRegistrationData(
identifier: "<id>",
identifier: "<unique-id>",
configuration: .init(strategy: .everyTime,
requiresNetworkConnectivity: true)) { completion in
//perform and call completion.
Expand Down

0 comments on commit a27a3e6

Please sign in to comment.