yonat / EasyBackgroundRefresh

Easy background refresh registration, scheduling, execution, and completion. BGTaskScheduler for the lazy.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EasyBackgroundRefresh

Easy background refresh registration, scheduling, execution, and completion. BGTaskScheduler for the lazy.

Swift Version License CocoaPods Compatible Platform PRs Welcome

Usage

For fast refreshes:

struct MyApp: App {

    let backgroundRefresh = EasyBackgroundRefresh(autoCompleteDelay: 3) { _ in
        // quickly refresh your data in less than autoCompleteDelay seconds
    }
    
    ...
}

For longer refreshes:

struct MyApp: App {

    let backgroundRefresh = EasyBackgroundRefresh { backgroundRefresh in
        backgroundRefresh.isProcessing = true
        defer { backgroundRefresh.isProcessing = false }
        // refresh your data, take up to 30 seconds
    }
    
    ...
}

Note:

Remember to enable background refresh and add Info.plist keys as described in Apple docs.

By default, EasyBackgroundRefresh uses your app Bundle ID as the background task ID. You can change that by passing a different value to init:

let backgroundRefresh = EasyBackgroundRefresh(taskIdentifier: "io.another.identifier")

Installation

CocoaPods:

pod 'EasyBackgroundRefresh'

Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/yonat/EasyBackgroundRefresh", from: "1.0.2")
]

About

Easy background refresh registration, scheduling, execution, and completion. BGTaskScheduler for the lazy.

License:MIT License


Languages

Language:Swift 80.9%Language:Ruby 19.1%