flutter_workmanager icon indicating copy to clipboard operation
flutter_workmanager copied to clipboard

🐞[iOS] callbackDispatcher is not execute when using the Workmanager().registerOneOffTask

Open SuryaChinnadurai1997 opened this issue 2 years ago • 15 comments

I have checkout the example folder in the workmanager package and then ran the example in the iOS platform. But the callbackDispatcher is not execute when i resister registerOneOffTask. It's happens in the iphone real device

Code snippet:

https://github.com/fluttercommunity/flutter_workmanager/tree/main/example

Version

Technology Version
Workmanager version ^0.5.1
Xcode version 14.3
Swift version 5.8
iOS deployment target 13.0

Describe the error Background task is not execute.

Output of flutter doctor -v [✓] Flutter (Channel stable, 3.10.5, on macOS 13.1 22C65 darwin-arm64, locale en-US) • Flutter version 3.10.5 on channel stable at /Users/samv/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 796c8ef792 (4 weeks ago), 2023-06-13 15:51:02 -0700 • Engine revision 45f6e00911 • Dart version 3.0.5 • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at /Users/samv/Library/Android/sdk • Platform android-33, build-tools 32.1.0-rc1 • ANDROID_HOME = /Users/samv/Library/Android/sdk • ANDROID_SDK_ROOT = /Users/samv/Library/Android/sdk • Java binary at: /Applications/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 14.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E222b • CocoaPods version 1.12.1

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.80.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.68.0

[✓] Connected device (3 available) • iPhone 14 Pro (mobile) • FAC97301-5BBE-422A-BECE-BD7361EB3013 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.1 22C65 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 114.0.5735.198

[✓] Network resources • All expected network resources are available.

• No issues found!

SuryaChinnadurai1997 avatar Jul 11 '23 13:07 SuryaChinnadurai1997

Any solution to this? same here and is not working on ios

acamue avatar Jul 31 '23 23:07 acamue

@acamue No. Still i didn't get any solution

SuryaChinnadurai1997 avatar Aug 14 '23 04:08 SuryaChinnadurai1997

Mine iPhone XR, iOS 17.0.2 got this error:

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(bgTaskSchedulingFailed(Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)") error, Scheduling the task using BGTaskScheduler has failed.

This may be due to too many tasks being scheduled but not run.

See the error for details: Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)"., null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
<asynchronous suspension>
#2      Workmanager.registerOneOffTask (package:workmanager/src/workmanager.dart:192:7)
<asynchronous suspension>

Working well on Android

f1dz avatar Oct 04 '23 08:10 f1dz

Did you test it on a real device and is Background App Refresh enabled in Settings?

xunreal75 avatar Oct 04 '23 10:10 xunreal75

Did you test it on a real device and is Background App Refresh enabled in Settings?

Yes. I tested in the iPhone real device and the Background App Refresh enabled in that device.

SuryaChinnadurai1997 avatar Oct 05 '23 04:10 SuryaChinnadurai1997

callbackDispatcher() is not executing in ios. Is any one have a solution?

ranjanSoumyaDO avatar Oct 10 '23 10:10 ranjanSoumyaDO

I have one off tasks working on iOS

Pull in this branch in your pubspec.yaml

  workmanager:
    git:
      url: https://github.com/absar/flutter_workmanager.git
      ref: ios-bg-tasks-enh-final

And you must set debug to true when initializing in main.dart

  Workmanager().initialize(callbackDispatcher, isInDebugMode: true);

scottynoshotty avatar Oct 20 '23 18:10 scottynoshotty

@scottynoshotty Apply that package and it should work fine. Thanks.

synstin avatar Nov 05 '23 11:11 synstin

@scottynoshotty Using the package you provided, callbackDispatcher is called normally, but no delay is applied. Even if you set the delay option, callbackDispatcher is called immediately. (Only on ios)

synstin avatar Nov 06 '23 02:11 synstin

hi guys, what about Workmanager().registerPeriodicTask() ? on ios still do not work? i tryied the the solution @scottynoshotty but it works only on registerOneOffTask... i need to run a periodic work, anybody have a solution?

AntonioVerdiglione1996 avatar Feb 28 '24 11:02 AntonioVerdiglione1996

@AntonioVerdiglione1996 i need periodic too, can you resolve this issue?

andersonribeir avatar May 21 '24 18:05 andersonribeir

Can someone help how to resolve it?

SuryaCinnadurai avatar Jun 22 '24 03:06 SuryaCinnadurai

+1

noeGnh avatar Jul 10 '24 11:07 noeGnh