Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ios bg tasks enhancements final #3

Merged
merged 22 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
08bd327
Merge pull request #1 from presence-app/main
absar Sep 11, 2023
8d184da
Format readme iOS examples
absar Sep 14, 2023
b06db87
Improve code documentation
absar Sep 18, 2023
7f807fe
Cleanups in SwiftWorkmanagerPlugin.swift
absar Sep 18, 2023
2fb38eb
* iOS, Rename registeriOSBackgroundProcessingTask to a generic name r…
absar Sep 18, 2023
2af1f55
* Cleanup code to make it more close to original plugin so that chang…
absar Sep 20, 2023
3558258
Add task identifiers to iOS AppRefresh and ProcessingTask so that use…
absar Sep 20, 2023
43df000
* iOS AppRefresh task interval should be 15 minutes
absar Sep 20, 2023
1bd6a6b
Initialize should not auto open App settings if background refresh pe…
absar Sep 21, 2023
222bdad
Continue work on task identifiers for iOS AppRefresh and ProcessingTask.
absar Sep 22, 2023
5d9ce95
Temporary merge branch 'ios-BGTaskScheduler-enhancements' into ios-ta…
absar Sep 23, 2023
9652d83
Merge pull request #2 from fluttercommunity/main
absar Sep 23, 2023
39aad70
Merge iOS enhancements into latest workmanager main branch
absar Sep 24, 2023
7c256ae
Fix extra commas on iOS
absar Sep 24, 2023
8a6f560
New iOS feature printScheduledTasks to print details of un-executed s…
absar Sep 26, 2023
9625658
iOS Periodic and processing tasks will be immediately scheduled, inst…
absar Sep 26, 2023
196bad2
Option to set frequency for iOS periodic tasks in AppDelegate.swift
absar Sep 27, 2023
5a8cbf2
Update iOS docs
absar Sep 27, 2023
c59058d
TODO for cleanups later
absar Sep 27, 2023
03e1edb
Branch all iOS developments to prepare merging to original workmanager
absar Sep 27, 2023
370df0c
mark version 0.5.2
ened Sep 28, 2023
f3e717b
Sync with master
absar Oct 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
package-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: axel-op/dart-package-analyzer@v3
with:
# Required:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
example_android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- uses: subosito/flutter-action@v2
with:
channel: "stable"
Expand All @@ -25,7 +25,7 @@ jobs:
example_ios:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
channel: "stable"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
format_dart:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
Expand All @@ -23,22 +23,22 @@ jobs:

steps:
- name: "checkout"
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: "ktlint"
uses: "vroy/gha-kotlin-linter@v1"

format_swift:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: GitHub Action for SwiftLint
uses: norio-nomura/[email protected]

publishable:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Pull-Request Check"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: marocchino/sticky-pull-request-comment@v2
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.lint_pr_title.outputs.error_message != null)
with:
header: pr-title-lint-error
message: |
Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.

Details:

```
${{ steps.lint_pr_title.outputs.error_message }}
```

# Delete a previous comment when the issue has been resolved
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
delete: true
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
Expand All @@ -22,7 +22,7 @@ jobs:
native_ios_tests:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
Expand All @@ -34,10 +34,10 @@ jobs:
native_android_tests:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- uses: subosito/flutter-action@v1
with:
channel: 'stable'
Expand All @@ -57,7 +57,7 @@ jobs:
- uses: futureware-tech/simulator-action@v1
with:
model: '${{ matrix.device }}'
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
Expand All @@ -76,10 +76,10 @@ jobs:
# api-level: [21, 29]
target: [default]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# next
# 0.5.2

* Android: Bump to workmanager 2.8.1
* Android: Move to Android Gradle Plugin 8.x
* Android: Migrate away from ResolvableFuture (#399).

# 0.5.1
Expand Down
28 changes: 23 additions & 5 deletions IOS_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This plugin is compatible with **Swift 4.2** and up. Make sure you are using **X
> ⚠️ BGTaskScheduler is similar to Background Fetch described below and brings a similar set of constraints. Most notably, there are no guarantees when the background task will be run. Excerpt from the documentation:
>
> Schedule a processing task request to ask that the system launch your app when conditions are favorable for battery life to handle deferrable, longer-running processing, such as syncing, database maintenance, or similar tasks. The system will attempt to fulfill this request to the best of its ability within the next two days as long as the user has used your app within the past week.
>
> Workmanager BGTaskScheduler methods `registerOneOffTask`, `registerPeriodicTask`, and `registerProcessingTask` are only available on iOS 13+

![Screenshot of Background Fetch Capabilities tab in Xcode ](.art/ios_background_mode_background_processing.png)

Expand All @@ -19,6 +21,9 @@ This will add the **UIBackgroundModes** key to your project's `Info.plist`:
<key>UIBackgroundModes</key>
<array>
<string>processing</string>

<!-- If you need periodic tasks in iOS 13+ you need to enable Background Fetch as well -->
<string>fetch</string>
</array>
```

Expand All @@ -31,16 +36,25 @@ import workmanager

``` swift
// In AppDelegate.application method
WorkmanagerPlugin.registerTask(withIdentifier: "task-identifier")
WorkmanagerPlugin.registerBGProcessingTask(withIdentifier: "task-identifier")

// Register a periodic task in iOS 13+
WorkmanagerPlugin.registerPeriodicTask(withIdentifier: "be.tramckrijte.workmanagerExample.iOSBackgroundAppRefresh", frequency: NSNumber(value: 20 * 60))
```

- Info.plist
``` xml
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>task-identifier</string>
</array>
<array>
<string>task-identifier</string>

<!-- Register a periodic task in iOS 13+ -->
<string>be.tramckrijte.workmanagerExample.iOSBackgroundAppRefresh</string>
</array>
```
> ⚠️ On iOS 13+, adding a `BGTaskSchedulerPermittedIdentifiers` key to the Info.plist for new `BGTaskScheduler` API disables the `performFetchWithCompletionHandler` and `setMinimumBackgroundFetchInterval`
methods, which means you cannot use both old Background Fetch and new `registerPeriodicTask` at the same time, you have to choose one based on your minimum iOS target version.
For details see [Apple Docs](https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/using_background_tasks_to_update_your_app)

And will set the correct *SystemCapabilities* for your target in the `project.pbxproj` file:

Expand All @@ -64,7 +78,11 @@ e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWith

## Enabling Background Fetch

> ⚠️ Background fetch is one supported way to do background work on iOS with work manager: **Periodic tasks** are available on Android only for now! (see #109)
> ⚠️ Background fetch is one supported way to do background work on iOS with work manager. Note that this API is deprecated starting iOS 13, however it still works on iOS 13+ as of writing this article

> ⚠️ On iOS 13+, adding a `BGTaskSchedulerPermittedIdentifiers` key to the Info.plist for new `BGTaskScheduler` API disables the `performFetchWithCompletionHandler` and `setMinimumBackgroundFetchInterval`
methods, which means you cannot use both old Background Fetch and new `registerPeriodicTask` at the same time, you have to choose one based on your minimum iOS target version.
For details see [Apple Docs](https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/using_background_tasks_to_update_your_app)

Background fetching is very different compared to Android's Background Jobs.
In order for your app to support Background Fetch, you have to add the *Background Modes* capability in Xcode for your app's Target and check *Background fetch*:
Expand Down
Loading
Loading