GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - vrtdev/ios-workmanager: An iOS framework that encapsulates the iOS 13 BackgroundTasks API for easier scheduling of background work

BranchesTags
Open more actions menu

Latest commit

 

History

3 Commits
3 Commits

Folders and files

NameName
Last commit message
Last commit date
Example
Example
 
 
Workmanager/Classes
Workmanager/Classes
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
Workmanager.podspec
Workmanager.podspec
 
 
_Pods.xcodeproj
_Pods.xcodeproj
 
 

Repository files navigation

iOS WorkManager

iOS WorkManager is a wrapper around BackgroundTasks

Currently only proccesing tasks are supported

It is useful to run periodic tasks, such as fetching remote data on a regular basis.

Installation

Setup

Before you can schedule a background task, you must register each task with a unique identifier in your project's Info.plist:

<key>BGTaskSchedulerPermittedIdentifiers</key>
	<array>
		<string>be.vrt.ios-workmanager.oneoffbackgroundtask</string>
		<string>be.vrt.ios-workmanager.recurringbackgroundtask</string>
	</array>

Also add required UIBackgroundModes:

<key>UIBackgroundModes</key>
	<array>
		<string>processing</string>
	</array>

Registering a task

Register a task inside your AppDelegate didFinishLaunchingWithOptions and provide a callback for when the task is executed:

WorkManager.shared.registerTask(withIdentifier: "be.vrt.ios-workmanager.oneoffbackgroundtask") { task in
    self.handleOneOffTrigger(task: task as! BGProcessingTask)
}

Schedule a task

Two kinds of background tasks can be registered :

  • One off task : runs only once
  • Periodic tasks : runs indefinitely on a regular basis

To schedule a one off task:

WorkManager.shared.scheduleOneOffTask(withIdentifier: "be.vrt.ios-workmanager.oneoffbackgroundtask", name: "update_something")

To schedule a periodic task:

WorkManager.shared.schedulePeriodicTask(withIdentifier: "be.vrt.ios-workmanager.recurringbackgroundtask", name: "update_something", frequency: 900)

Properties

Initial Delay

Indicates how along a task should wait before its first run.

WorkManager.shared.schedulePeriodicTask(withIdentifier: "be.vrt.ios-workmanager.recurringbackgroundtask", name: "update_something", frequency: 900, initialDelay: 900)

Existing Work Policy

Indicates the desired behaviour when the same task is scheduled more than once.
The default is KEEP

WorkManager.shared.scheduleOneOffTask(withIdentifier: "be.vrt.ios-workmanager.oneoffbackgroundtask", name: "update_something", existingWorkPolicy: .replace)

Constraints

WorkManager.shared.schedulePeriodicTask(withIdentifier: "be.vrt.ios-workmanager.recurringbackgroundtask", name: "update_something", frequency: 900, constraints: [.requiresExternalPower, .requiresNetworkConnectivity])

BackoffPolicy

Indicates the waiting strategy upon task failure.
You can also specify the delay.

WorkManager.shared.schedulePeriodicTask(withIdentifier: "be.vrt.ios-workmanager.recurringbackgroundtask", name: "update_something", frequency: 900,backoffPolicy: .exponential, backoffPolicyDelay: 500)

Cancel a task

A task can be cancelled in different ways :

With identifier

WorkManager.shared.cancelTask(withIdentifier identifier: "")

With tag

WorkManager.shared.cancelTask(withTag tag: "")

All

WorkManager.shared.cancelAllTasks()

Example

See example project

About

An iOS framework that encapsulates the iOS 13 BackgroundTasks API for easier scheduling of background work

Resources

Readme
MIT license
Activity
Custom properties

Stars

18 stars

Watchers

16 watching

Forks

9 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.