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

workmanager not work on IOS Side. #455

Closed
JayswalViraj opened this issue Feb 14, 2023 · 26 comments
Closed

workmanager not work on IOS Side. #455

JayswalViraj opened this issue Feb 14, 2023 · 26 comments

Comments

@JayswalViraj
Copy link

JayswalViraj commented Feb 14, 2023

workmanager not work on IOS Side.

@JayswalViraj
Copy link
Author

I get this error when i run app in ios side:

PlatformException(bgTaskSchedulingFailed(Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)") error, Scheduling the task using BGTaskScheduler has failed.
flutter:
flutter: This may be due to too many tasks being scheduled but not run.
flutter:
flutter: See the error for details: Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)"., null, null)

@JayswalViraj JayswalViraj changed the title Work Manfer workmanager not work on IOS Side. Feb 14, 2023
@JayswalViraj
Copy link
Author

if you have proper code with ios setup please give me.

@xunreal75
Copy link
Contributor

@Mkohm
Copy link

Mkohm commented Feb 17, 2023

For me the example app is not working. No error messages and no output in the console, the callback is not being invoked it seems. Sad, since it works great on Android! I really need this plugin and would gladly pay the maintainer a small amount for continuing to maintain the plugin!

@wajahat414
Copy link

Yes IOS part the example app is not working getting the same error

@JayswalViraj
Copy link
Author

JayswalViraj commented Mar 3, 2023

Yes, It is still not working. Have you any solution plugin owner or anyone ?

@wajahat414
Copy link

Did you tried configuration for IOS?? And checked your background service timer?? It's 15 minutes I guess

@AyeshaIftikhar
Copy link

I have done all the required configuration and it is still not working for me on physical ios device

@wajahat414
Copy link

wajahat414 commented Mar 9, 2023 via email

@xunreal75
Copy link
Contributor

Did you tried configuration for IOS?? And checked your background service timer?? It's 15 minutes I guess

On iOS is no 15min timer. The operating system calls randomly the BGTask

@AyeshaIftikhar
Copy link

Is it working on simulator??

On Thu, 9 Mar 2023, 4:48 pm Ayesha Iftikhar, @.> wrote: I have done all the required configuration and it is still not working for me on physical ios device — Reply to this email directly, view it on GitHub <#455 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARN5JR3GAUXMDWOE5JU646LW3HGSBANCNFSM6AAAAAAU3W7ZQI . You are receiving this because you commented.Message ID: @.>

No throwing the same error on both stimulator and physical device.

@wajahat414
Copy link

wajahat414 commented Mar 10, 2023 via email

@AyeshaIftikhar
Copy link

Then another way is to create a custom plugin for yourself or try to register background service through method channel in iOS, or maybe you need to recheck the configuration you performed on ios On Fri, 10 Mar 2023, 10:13 am Ayesha Iftikhar, @.> wrote:

Is it working on simulator?? … <#m_-752857866688614986_> On Thu, 9 Mar 2023, 4:48 pm Ayesha Iftikhar, @.
> wrote: I have done all the required configuration and it is still not working for me on physical ios device — Reply to this email directly, view it on GitHub <#455 (comment) <#455 (comment)>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARN5JR3GAUXMDWOE5JU646LW3HGSBANCNFSM6AAAAAAU3W7ZQI https://github.com/notifications/unsubscribe-auth/ARN5JR3GAUXMDWOE5JU646LW3HGSBANCNFSM6AAAAAAU3W7ZQI . You are receiving this because you commented.Message ID: @.
> No throwing the same error on both stimulator and physical device. — Reply to this email directly, view it on GitHub <#455 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARN5JR5QX5SMQSR4GMCLSPLW3LBA5ANCNFSM6AAAAAAU3W7ZQI . You are receiving this because you commented.Message ID: @.
**>

Will give it a shot

@erichorlait
Copy link

I follow all the steps (I think so) in the configuration recipe! I copied the code from the example folder and I got the error:

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
message_codecs.dart:653
#1 MethodChannel._invokeMethod
platform_channel.dart:296
#2 Workmanager.registerOneOffTask
workmanager.dart:192

Does somebody have a running simple example of the use of this package?

Thanks

@ened
Copy link
Collaborator

ened commented Jun 3, 2023

a) do not run in the simulator.
b) ensure you read readme & the example works

@ened ened closed this as completed Jun 3, 2023
@vishweshsoni
Copy link

vishweshsoni commented Oct 24, 2023

@ened
I am able to test in iPhone using below command
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"workmanager.background.task"]
but without this command it is not working
i am missing anything ?

@abhinovpankaj
Copy link

Any solution to this issue? Why this issue has been marked as closed.

@DominicGBauer
Copy link

It's not in the ReadMe but you can't run background tasks in simulator https://developer.apple.com/documentation/backgroundtasks/bgtaskscheduler/error/code/unavailable

@vuzzer
Copy link

vuzzer commented Feb 27, 2024

Workmanager package doesn't work for ios

IOS 17 Xcode 15, library version 0.5.1

@Flutter36
Copy link

Hi,

I am trying to run periodic task on ios with below code and settings. Unfortunately, the task isnt getting triggered. Any help would be appreciated.

Swift code:

import UIKit
import Flutter
import workmanager

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
self.window.makeSecure()
GeneratedPluginRegistrant.register(with: self)
UNUserNotificationCenter.current().delegate = self
WorkmanagerPlugin.setPluginRegistrantCallback { registry in
// Registry in this case is the FlutterEngine that is created in Workmanager's
// performFetchWithCompletionHandler or BGAppRefreshTask.
// This will make other plugins available during a background operation.
GeneratedPluginRegistrant.register(with: registry)
}

WorkmanagerPlugin.registerPeriodicTask(withIdentifier: "com.background_task_manager.token_refresh_task", frequency: NSNumber(value: 20*60))
//UIApplication.shared.setMinimumBackgroundFetchInterval(TimeInterval(20*60));

return super.application(application, didFinishLaunchingWithOptions: launchOptions)

}

override func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler(.alert) // shows banner even if app is in foreground
}
}

extension UIWindow {
func makeSecure() {
let isTestFlight = Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
let isSecureMode = Bundle.main.object(forInfoDictionaryKey: "EnableSecureMode") as! String == "YES"
if (isTestFlight || !isSecureMode) {
return
}

let field = UITextField()
let view = UIView(frame: CGRect(x: 0, y: 0, width: field.frame.self.width, height: field.frame.self.height))
field.isSecureTextEntry = true
self.addSubview(field)
self.layer.superlayer?.addSublayer(field.layer)
field.layer.sublayers?.last!.addSublayer(self.layer)
field.leftView = view
field.leftViewMode = .always

}
}

version of the library used

workmanager:
git:
url: https://github.com/absar/flutter_workmanager.git
ref: 73cc539

Target platform an other details:

platform :ios, '13.0'

Code to trigger period task

      Workmanager().registerPeriodicTask(
  BackgroundTaskKeys.refreshTokenTaskName, // Unique ID for your task
  BackgroundTaskKeys.refreshTokenTaskName,
  initialDelay: Duration(seconds: 10),
  frequency: Duration(seconds: 20*60)
);


Info LIst params

		<key>UIBackgroundModes</key>
    <array>
	    <string>fetch</string>
	    <string>processing</string>
    </array>
    
    
    		<key>BGTaskSchedulerPermittedIdentifiers</key>
    <array>
	    <string>com.kdi.background_task_manager.token_refresh_task</string>
    </array>

@vuzzer
Copy link

vuzzer commented Mar 18, 2024

Hi @Flutter36
I personnally use flutter_background_service: ^5.0.5 to run task in background. It works well.
link package: https://pub.dev/packages/flutter_background_service

@isystemsdevops
Copy link

Hi @Flutter36 I personnally use flutter_background_service: ^5.0.5 to run task in background. It works well. link package: https://pub.dev/packages/flutter_background_service

can it be used to run a function onetime at a specific time? or periodically like once a day?

@vuzzer
Copy link

vuzzer commented Mar 23, 2024

Hi @Flutter36 I personnally use flutter_background_service: ^5.0.5 to run task in background. It works well. link package: https://pub.dev/packages/flutter_background_service

can it be used to run a function onetime at a specific time? or periodically like once a day?

Of course, You can do it !

@imasif
Copy link

imasif commented Nov 21, 2024

Hi @Flutter36 I personnally use flutter_background_service: ^5.0.5 to run task in background. It works well. link package: https://pub.dev/packages/flutter_background_service

can it be used to run a function onetime at a specific time? or periodically like once a day?

Of course, You can do it !

@vuzzer I want to run a task after 2 minutes, is it possible? can you share some code?

@vuzzer
Copy link

vuzzer commented Nov 21, 2024

Hi @Flutter36 I personnally use flutter_background_service: ^5.0.5 to run task in background. It works well. link package: https://pub.dev/packages/flutter_background_service

can it be used to run a function onetime at a specific time? or periodically like once a day?

Of course, You can do it !

@vuzzer I want to run a task after 2 minutes, is it possible? can you share some code?

Hi @imasif, here's a simple example of a task that updates data every minute :

 late Timer timer;
  @override
  void initState() {
    // Sets up a periodic Timer to call the `refreshData` method every 60 seconds.
    timer = Timer.periodic(const Duration(seconds: 60), (timer) {
        refreshData();
    });
    super.initState();
  }


  @override
  void dispose() {
    timer.cancel();
  }

  void refreshData() {
  // Executes a data refresh task.
  // This task can run on a separate thread using packages `flutter_background_task`
  // ensuring it doesn't block the main UI thread.
  }

hope this helps !

@imasif
Copy link

imasif commented Nov 21, 2024

Hi @Flutter36 I personnally use flutter_background_service: ^5.0.5 to run task in background. It works well. link package: https://pub.dev/packages/flutter_background_service

can it be used to run a function onetime at a specific time? or periodically like once a day?

Of course, You can do it !

@vuzzer I want to run a task after 2 minutes, is it possible? can you share some code?

Hi @imasif, here's a simple example of a task that updates data every minute :

 late Timer timer;
  @override
  void initState() {
    // Sets up a periodic Timer to call the `refreshData` method every 60 seconds.
    timer = Timer.periodic(const Duration(seconds: 60), (timer) {
        refreshData();
    });
    super.initState();
  }


  @override
  void dispose() {
    timer.cancel();
  }

  void refreshData() {
  // Executes a data refresh task.
  // This task can run on a separate thread using packages `flutter_background_task`
  // ensuring it doesn't block the main UI thread.
  }

hope this helps !

@vuzzer I don't want it to be periodic, it will only run once when I start the scheduler, everytime I call the scheduler and it will execute after 2minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests