flutter_workmanager icon indicating copy to clipboard operation
flutter_workmanager copied to clipboard

[Doc] IOS callback not called

Open ghost opened this issue 2 years ago • 15 comments

  • [x] I have read the README
  • [x] I have done the setup for Android
  • [x] I have done the setup for iOS
  • [x] I have ran the sample app and it does not work there

Version flutter 2.10.3

Technology Version
Workmanager version 0.5.0-dev.8
Xcode version 13.3.1
Swift version
iOS deployment target 11

Describe the error Describe error Optionally provide the least amount of code that shows this behaviour. Ideally in the sample app.

void callbackDispatcher() {
  debugPrint("test");
  Workmanager().executeTask((
    String task,
    Map<String, dynamic>? json,
  ) async {
    debugPrint("test 2");
    return true;
  }
}  
await Workmanager().initialize(
      callbackDispatcher,
      isInDebugMode: kDebugMode,
    );
Workmanager().registerOneOffTask(
"workmanager.background.task",
"workmanager.background.task",
tag: "workmanager.background.task",
)

The callback is never called on iOS, despite the fact that it works on Android... I've done all the iOS setup part with 'workmanager.background.task' as task identifier because i use WorkManager 0.5.0-dev.8

Output of flutter doctor -v

[✓] Flutter (Channel stable, 2.10.3, on macOS 12.3.1 21E258 darwin-arm, locale fr-FR)
    • Flutter version 2.10.3 at /Users/*********/fvm/versions/2.10.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (3 months ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/*********/Library/Android/Sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • ANDROID_HOME = /Users/**********/Library/Android/Sdk
    • Java binary at: /Users/********/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/212.5712.43.2112.8609683/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Connected device (2 available)
    • iPhone de ******** (mobile) • 037a70ff3ad9e7787722c6c239f94d2aadceb764 • ios            • iOS 15.4.1 19E258
    • Chrome (web)                  • chrome                                   • web-javascript • Google Chrome 102.0.5005.61

ghost avatar May 31 '22 16:05 ghost

https://github.com/fluttercommunity/flutter_workmanager/issues/397

ghost avatar Jun 02 '22 12:06 ghost

To run background processing : you need to run app on xcode and put a breakpoint after register your task. On xcode breakpoint console, run the following command and then continue your app :

e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"workmanager.background.task"]

ghost avatar Jun 02 '22 12:06 ghost

Need to update doc.

ghost avatar Jun 02 '22 12:06 ghost

Doc should mention how to stop ios background processing :

 e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateExpirationForTaskWithIdentifier:@"workmanager.background.task"]

ghost avatar Jun 03 '22 14:06 ghost

Any way to avoid doing these tricks (breakpoint + command) while developing on IOS ?

ghost avatar Jun 03 '22 14:06 ghost

I run the following code after breakpoint e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateExpirationForTaskWithIdentifier:@"workmanager.background.task"] but I'm getting this error Error [IRForTarget]: Couldn't resolve the class for an Objective-C static method call

ibrahimcss avatar Jun 12 '22 12:06 ibrahimcss

To run background processing : you need to run app on xcode and put a breakpoint after register your task. On xcode breakpoint console, run the following command and then continue your app :

e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"workmanager.background.task"]

Are there any ways to debug the dart code after using this trick?

dev-ltk avatar Aug 29 '22 09:08 dev-ltk

I also want to know if there are any ways to debug dart code after doing this.

Gibbo97 avatar Nov 09 '22 06:11 Gibbo97

I also have this problem. Does the Workmanager Plugin not work for iOS? Did some of the people here solve this problem?

maxmitz avatar Dec 08 '22 14:12 maxmitz

Any updates? Same problem Flutter Channel stable, 3.7.0

iSamodurov avatar Feb 04 '23 22:02 iSamodurov

Any update on this?

ariefwijaya avatar Feb 11 '23 15:02 ariefwijaya

I get the impression the Workmanger plugin does work on iOS, as I can put a breakpoint after registering, and then do the simulate launch. This method needs to be written in the iOS setup doc, because referencing Apple's "Starting and Terminating Tasks During Development" does not help.

The problem is that when calling registerOneOffTask it does not fire the callback. Which has now newly created issue #450.

NebulaFox avatar Mar 14 '23 15:03 NebulaFox

yes, this issue still exists. But only while using the simulator. I have tested this with a real device. Despite passing Duration.zero for initialDelay and despite the comment in the example "Most likely this will trigger immediately", it took 15 minutes until the task got executed. When triggering a background fetch with Xcode (described in the iOS setup guide) the task executes immediately.

felixriehm avatar Apr 03 '23 17:04 felixriehm

I just run the example, it not work on iOS......

Unhandled Exception: PlatformException(bgTaskSchedulingFailed(Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)") error, Scheduling the task using BGTaskScheduler has failed.

luohao123 avatar May 17 '23 13:05 luohao123

I just run the example, it not work on iOS......

Unhandled Exception: PlatformException(bgTaskSchedulingFailed(Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)") error, Scheduling the task using BGTaskScheduler has failed.

#441

McFamous avatar May 31 '23 13:05 McFamous