fluttercommunity / flutter_workmanager

A Flutter plugin which allows you to execute code in the background on Android and iOS.
859 stars 275 forks source link

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

Open SuryaChinnadurai1997 opened 1 year ago

SuryaChinnadurai1997 commented 1 year ago

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!

acamue commented 1 year ago

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

SuryaChinnadurai1997 commented 1 year ago

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

f1dz commented 1 year ago

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

xunreal75 commented 1 year ago

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

SuryaChinnadurai1997 commented 1 year ago

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.

ranjanSoumyaDO commented 1 year ago

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

scottynoshotty commented 1 year ago

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);
synstin commented 1 year ago

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

synstin commented 1 year ago

@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)

AntonioVerdiglione1996 commented 8 months ago

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?

andersonribeir commented 6 months ago

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

SuryaCinnadurai commented 5 months ago

Can someone help how to resolve it?

noeGnh commented 4 months ago

+1

AhmedAlaaGenina commented 1 month ago

Workmanager().registerPeriodicTask() not work on ios Any idea ?

nguyendaihongquan-dev commented 1 month ago

Workmanager().registerPeriodicTask() not work on ios The same idea ?