Skip to content

Commit

Permalink
release: 8.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev-hwang committed Sep 23, 2024
1 parent 8b7c77b commit ad56272
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 8.9.0

* [**CHANGE**] Ignore `autoRunOnBoot` option when service is stopped by developer
* [**CHANGE**] Ignore `autoRunOnBoot` option when android:stopWithTask is set to true
* [**FEAT**] Add TaskStarter to check who started the task [#276](https://github.com/Dev-hwang/flutter_foreground_task/issues/276)
- Add `starter` parameter to `onStart` callback of TaskHandler
- `.developer`: The task has been started by the developer (startService, restartService, updateService)
- `.system`: The task has been started by the system (reboot, app-updates, AlarmManager-restart)
* [**FEAT-iOS**] Allow background app refresh
- Bump iOS minimumVersion to 13.0
- You need to add `BGTaskSchedulerPermittedIdentifiers` key in `ios/Runner/info.plist` file
- Check [Getting started-iOS](https://pub.dev/packages/flutter_foreground_task#baby_chick-ios) for more details

## 8.8.1+1

* [**DOCS**] Update example to see two-way communication flow
Expand Down
56 changes: 34 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,34 @@ This plugin is used to implement a foreground service on the Android platform.
* Provides useful utilities that can use while performing tasks.
* Provides option to automatically resume the foreground service on boot.

## Support version

- Flutter: `3.10.0+`
- Dart: `3.0.0+`
- Android: `5.0+ (minSdkVersion: 21)`
- iOS: `13.0+`

## Getting started

To use this plugin, add `flutter_foreground_task` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/). For example:

```yaml
dependencies:
flutter_foreground_task: ^8.8.1+1
flutter_foreground_task: ^8.9.0
```
After adding the `flutter_foreground_task` plugin to the flutter project, we need to specify the permissions and service to use for this plugin to work properly.

### :baby_chick: Android

Open the `AndroidManifest.xml` file and specify the service inside the `<application>` tag as follows.
Open the `AndroidManifest.xml` file and specify the service tag inside the `<application>` tag as follows.

If you want the foreground service to run only when the app is running, add `android:stopWithTask="true"` option.

As it is mentioned in the Android Guidelines, in Android 14, to start a FG service, you need to specify `android:foregroundServiceType`.
As mentioned in the Android guidelines, to start a FG service on Android 14+, you must specify `android:foregroundServiceType`.

You can read all the details in the Android Developer Page : https://developer.android.com/about/versions/14/changes/fgs-types-required

If you want to target Android 14 phones, you need to add a few lines to your manifest.
Change the type with your type (all types are listed in the link above).

```
<!-- required -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Expand All @@ -57,22 +61,37 @@ Change the type with your type (all types are listed in the link above).

Check runtime requirements before starting the service. If this requirement is not met, the foreground service cannot be started.

<img src="https://github.com/Dev-hwang/flutter_foreground_task/assets/47127353/2a35dada-2c82-41f4-8a45-56776c88e9d3" width="720">
<img src="https://github.com/Dev-hwang/flutter_foreground_task/assets/47127353/2a35dada-2c82-41f4-8a45-56776c88e9d3" width="700">

### :baby_chick: iOS

We can also launch `flutter_foreground_task` on the iOS platform. However, it has the following limitations.

* Works only on iOS 12.0 or later.
* If you force close an app in recent apps, the task will be destroyed immediately.
* The task cannot be started automatically on boot like Android OS.
* The task will run in the background for approximately 30 seconds due to background processing limitations. but it works fine in the foreground.
* The task runs in the background for approximately 30 seconds every 15 minutes. This may take longer than 15 minutes due to iOS limitations.

**Info.plist**:

Add the key below to `ios/Runner/info.plist` file so that the task can run in the background.

```text
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.pravera.flutter_foreground_task.refresh</string>
</array>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
</array>
```

**Objective-C**:

1. To use this plugin developed in Swift language in a project using Objective-C, you need to add a bridge header. If you don't have an `ios/Runner/Runner-Bridging-Header.h` file in your project, check this [page](https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_objective-c_into_swift).
To use this plugin developed in Swift in a project using Objective-C, you need to add a bridge header.
If there is no `ios/Runner/Runner-Bridging-Header.h` file in your project, check this [page](https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_objective-c_into_swift).

2. Open the `ios/Runner/AppDelegate.swift` file and add the commented code.
Open the `ios/Runner/AppDelegate.swift` file and add the commented code.

```objc
#import "AppDelegate.h"
Expand All @@ -92,7 +111,7 @@ void registerPlugins(NSObject<FlutterPluginRegistry>* registry) {
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
// here, without this code the task will not work.
// here
[FlutterForegroundTaskPlugin setPluginRegistrantCallback:registerPlugins];
if (@available(iOS 10.0, *)) {
[UNUserNotificationCenter currentNotificationCenter].delegate = (id<UNUserNotificationCenterDelegate>) self;
Expand All @@ -102,18 +121,17 @@ void registerPlugins(NSObject<FlutterPluginRegistry>* registry) {
}
@end
```

**Swift**:

1. Declare the import statement below in the `ios/Runner/Runner-Bridging-Header.h` file.
Declare the import statement below in the `ios/Runner/Runner-Bridging-Header.h` file.

```objc
#import <flutter_foreground_task/FlutterForegroundTaskPlugin.h>
```

2. Open the `ios/Runner/AppDelegate.swift` file and add the commented code.
Open the `ios/Runner/AppDelegate.swift` file and add the commented code.

```swift
import UIKit
Expand All @@ -127,7 +145,7 @@ import Flutter
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
// here, without this code the task will not work.
// here
SwiftFlutterForegroundTaskPlugin.setPluginRegistrantCallback(registerPlugins)
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
Expand All @@ -143,12 +161,6 @@ func registerPlugins(registry: FlutterPluginRegistry) {
}
```

**Configuring background execution modes**

Background mode settings are required for tasks to be processed in the background.

See this [page](https://developer.apple.com/documentation/xcode/configuring-background-execution-modes) for settings.

## How to use

### :hatched_chick: step by step
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_foreground_task
description: This plugin is used to implement a foreground service on the Android platform.
version: 8.8.1+1
version: 8.9.0
homepage: https://github.com/Dev-hwang/flutter_foreground_task

environment:
Expand Down

0 comments on commit ad56272

Please sign in to comment.