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

feat: Remove debugmode #548

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file removed .art/android_debug_notification.gif
Binary file not shown.
Binary file removed .art/ios_debug_notification_types.png
Binary file not shown.
Binary file removed .art/ios_debug_notifications.gif
Binary file not shown.
5 changes: 3 additions & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v1
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
java-version: '21'
- uses: subosito/flutter-action@v2
with:
channel: "stable"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/no-response.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
noResponse:
runs-on: ubuntu-latest
steps:
- uses: lee-dohm/no-response@v0.5.0
- uses: bugwelle/no-response-action@main
with:
token: ${{ github.token }}
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5.2.0
- uses: amannn/action-semantic-pull-request@v5.4.0
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
38 changes: 25 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,29 @@ jobs:
with:
channel: 'stable'
- name: Build iOS App
run: cd example && flutter build ios --debug --no-codesign
- name: Run native iOS tests
run: cd example/ios && xcodebuild -workspace Runner.xcworkspace -scheme Runner -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12,OS=16.2' test
run: |
dart pub global activate melos
melos bootstrap
cd example && flutter build ios --debug --no-codesign
cd ios && xcodebuild -workspace Runner.xcworkspace -scheme Runner -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12,OS=16.2' test

native_android_tests:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v1
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
java-version: '21'
- uses: subosito/flutter-action@v1
with:
channel: 'stable'
- name: Build Android App
run: cd example && flutter build apk --debug
- name: Run native Android tests
run: cd example/android && gradle workmanager:test
run: |
dart pub global activate melos
melos bootstrap
cd example && flutter build apk --debug
cd android && gradle workmanager:test

drive_ios:
strategy:
Expand All @@ -55,7 +60,7 @@ jobs:
fail-fast: false
runs-on: macos-latest
steps:
- uses: futureware-tech/simulator-action@v1
- uses: futureware-tech/simulator-action@v3
with:
model: '${{ matrix.device }}'
- uses: actions/checkout@v4
Expand All @@ -64,7 +69,10 @@ jobs:
channel: 'stable'
# Run flutter integrate tests
- name: Run Flutter integration tests
run: cd example && flutter test integration_test/workmanager_integration_test.dart
run: |
dart pub global activate melos
melos bootstrap
cd example && flutter test integration_test/workmanager_integration_test.dart


drive_android:
Expand All @@ -78,9 +86,10 @@ jobs:
target: [default]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v1
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
java-version: '21'
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
Expand All @@ -89,4 +98,7 @@ jobs:
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
script: cd example && flutter test integration_test/workmanager_integration_test.dart
script: |
dart pub global activate melos
melos bootstrap
cd example && flutter test integration_test/workmanager_integration_test.dart
18 changes: 0 additions & 18 deletions ANDROID_SETUP.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
# Check your AndroidManifest.xml

Check if you have the following in your `AndroidManifest.xml` file.

```xml
<meta-data
android:name="flutterEmbedding"
android:value="2" />
```

Ideally you should have this, if not follow the [upgrade guide](https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects).
If for some reason you can't upgrade yet we still support the [older way of embedding](ANDROID_SETUP_V1.md):

# How to Debug my background job

Debugging a background task can be difficult, Android decides when is the best time to run.
There is no guaranteed way to enforce a run of a job even in debug mode.

However to facilitate debugging, the plugin provides an `isInDebugMode` flag when initializing the plugin: `Workmanager().initialize(callbackDispatcher, isInDebugMode: true)`

Once this flag is enabled you will receive a notification whenever a background task was triggered.
This way you can keep track whether that task ran successfully or not.

<img src=".art/android_debug_notification.gif" height="650">
64 changes: 0 additions & 64 deletions IOS_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,70 +177,6 @@ If you launched your app using the Flutter command line tools or another IDE lik



## Debug mode

To make background work more visible when developing, the WorkManager plugin provides an `isInDebugMode` flag when initializing the plugin:

```dart
Workmanager().initialize(callbackDispatcher, isInDebugMode: true)
```

If `isInDebugMode` is `true`, a local notification will be displayed whenever a background fetch was triggered by iOS. In the example gif below, two background fetches were *simulated* in quick succession. Both completing succesfully after a few seconds in this case:

![example of iOS debug notification](.art/ios_debug_notifications.gif)



These are the three notification types, **start** work, finished **successfully**, finished with **failure**:

![example of iOS debug notification](.art/ios_debug_notification_types.png)

*Success* or *failure* depending on what you return in Dart:

```dart
bool success = true;
return Future.value(success);
```



If your app is running in the **foreground**, notification banners are **not shown**. That is default behaviour on iOS. Triggering *Simulate Background Fetch* when running on a **real device** will put the app in the background *first*, before calling the `performFetchWithCompletionHandler`. This doesn't happen in the Simulator. So, make sure to go to the Home screen *before* triggering background fetch.

> 📝 Note: the Home Indicator swipe-up gesture is sometimes tricky to do on a simulator. Use Simulator menu `Hardware` → `Home` or keyboard shortcut <kbd>⌘ command</kbd> + <kbd>⇧ shift</kbd> + <kbd>H</kbd> to make your life easier

### Show notifications in foreground

Alternatively, if you *do* want the banners to appear while your app is in the foreground you can implement `userNotificationCenter(_:willPresent:withCompletionHandler:)` of `UNUserNotificationCenterDelegate`.

From the [Apple docs](https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/1649518-usernotificationcenter):

> If your **app is in the foreground** when a notification arrives, the shared user **notification center calls this method to deliver the notification directly to your app**. If you implement this method, you can take whatever actions are necessary to process the notification and update your app. When you finish, **call the completionHandler block and specify how you want the system to alert the user**, if at all.

An easy way to get it working is by implementing it your `AppDelegate` like so:
```swift
class AppDelegate: FlutterAppDelegate {
// ...
override func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler(.alert) // shows banner even if app is in foreground
}

}
```

And assigning yourself as the delegate. Preferably as early as possible, in `application:didFinishLaunchingWithOptions:`

```swift
UNUserNotificationCenter.current().delegate = self
```

Now the banners **are** shown when your app is running in the foreground 👇

![Screenshot of Simulator with app in foreground showing notification banner](.art/ios_notification_foreground.png)

> 📝 Note: decide if implementing the delegate call makes sense for your app. You could make use of [active compilation conditions](https://blog.krzyzanowskim.com/2016/10/10/conditional-swift-testing/) to implement it *only* for the `Debug` configruation, for example



## Registered plugins
Expand Down
Loading
Loading