Flutter workmanager error Domain=BGTaskSchedulerErrorDomain Code=3 "(null)" on iOS

94 views Asked by At

i'm trying to use workermanger with flutter about background service on ios. So this is my plist

enter image description here

Now this is my AppDelegate on xcode:

 import UIKit
import Flutter
import workmanager


    @UIApplicationMain
    @objc 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
        }
        
    
        override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
            WorkmanagerPlugin.registerTask(withIdentifier: "simpleTask")
            UIApplication.shared.setMinimumBackgroundFetchInterval(TimeInterval(60*15))
            GeneratedPluginRegistrant.register(with: self)
            return super.application(application, didFinishLaunchingWithOptions: launchOptions)
        }
    }

and now this is my Flutter code

import 'package:workmanager/workmanager.dart';

@pragma('vm:entry-point')
void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) {
    switch (task) {
      case Workmanager.iOSBackgroundTask:
        print("The iOS background fetch was triggered");
        break;
    }
    bool success = true;
    return Future.value(success);
  });
}
void main() {
    WidgetsFlutterBinding.ensureInitialized();
   Workmanager().initialize(
    callbackDispatcher, // The top level function, aka callbackDispatcher
    isInDebugMode: true // If enabled it will post a notification whenever the task is running. Handy for debugging tasks
  );
  Workmanager().registerOneOffTask("simpleTask", "simpleTask");
  // Workmanager().registerPeriodicTask("simpleTask", "simpleTask");
  runApp(const MyApp());  
}

The error i receive is this:

Could not schedule app refresh: Error Domain=BGTaskSchedulerErrorDomain Code=3 "(null)"

can you suggest me where i'm lost? Maybe about the documentation, i can't understand i ask help to you.

0

There are 0 answers