I’m making an attempt to run workmanager package deal on IOS. It really works wonderful on android however would not work on IOS. I’m utilizing iphone 14 to check. I did setup for ios following iosSetup.
callbackDispatcher would not reply.
That is my key
const simpleTaskKey = "be.tramckrijte.workmanagerExample.simpleTask";
That is the operate that’s not responding in any respect
void callbackDispatcher() {
Workmanager().executeTask((process, inputData) async {
swap (process) {
case simpleTaskKey:
print("$simpleTaskKey was executed. inputData = $inputData");
closing prefs = await SharedPreferences.getInstance();
prefs.setBool("check", true);
print("Bool from prefs: ${prefs.getBool("check")}");
break;
case Workmanager.iOSBackgroundTask:
print("The iOS background fetch was triggered");
Listing? tempDir = await getTemporaryDirectory();
String? tempPath = tempDir.path;
print(
"You'll be able to entry different plugins within the background, for instance
Listing.getTemporaryDirectory(): $tempPath");
break;
}
return Future.worth(true);
});
}
code that initializes workmanager
ElevatedButton(
youngster: Textual content("Begin the Flutter background service"),
onPressed: () {
Workmanager().initialize(
callbackDispatcher,
isInDebugMode: true,
);
},
),
code to set off reisterOneOffTask
ElevatedButton(
youngster: const Textual content("Register OneOff Job"),
onPressed: () {
Workmanager().registerOneOffTask(
simpleTaskKey,
simpleTaskKey,
inputData: <String, dynamic>{
'int': 1,
'bool': true,
'double': 1.0,
'string': 'string',
'array': [1, 2, 3],
},
);
},
),
my information.plist
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>be.tramckrijte.workmanagerExample.simpleTask</string>
</array>
my AppDekegate.swift
import UIKit
import Flutter
import workmanager
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func utility(
_ utility: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
WorkmanagerPlugin.registerTask(withIdentifier:
"be.tramckrijte.workmanagerExample.simpleTask")
UIApplication.shared.setMinimumBackgroundFetchInterval(TimeInterval(/* Your Desired
Interval for Background Duties */))
return tremendous.utility(utility, didFinishLaunchingWithOptions: launchOptions)
}
}