File tree Expand file tree Collapse file tree 2 files changed +17
-18
lines changed
Expand file tree Collapse file tree 2 files changed +17
-18
lines changed Original file line number Diff line number Diff line change @@ -53,31 +53,32 @@ iOS requires a 5-minute setup in Xcode:
5353``` swift
5454import workmanager
5555
56- // In application(_:didFinishLaunchingWithOptions:)
57- WorkmanagerPlugin.registerBGProcessingTask (withIdentifier : " your.task.identifier" )
56+ // In application didFinishLaunching
57+ WorkmanagerPlugin.registerBGProcessingTask (
58+ withIdentifier : " your.task.identifier"
59+ )
5860```
5961
6062## Basic Usage
6163
6264### 1. Create Background Task Handler
6365
6466``` dart
65- @pragma('vm:entry-point') // Required for release builds
67+ @pragma('vm:entry-point')
6668void callbackDispatcher() {
6769 Workmanager().executeTask((task, inputData) async {
6870 print("Background task: $task");
6971
70- // Your background logic here
7172 switch (task) {
7273 case "data_sync":
7374 await syncDataWithServer();
7475 break;
75- case "cleanup":
76+ case "cleanup":
7677 await cleanupOldFiles();
7778 break;
7879 }
7980
80- return Future.value(true); // Task completed successfully
81+ return Future.value(true);
8182 });
8283}
8384```
@@ -86,10 +87,9 @@ void callbackDispatcher() {
8687
8788``` dart
8889void main() {
89- // Initialize Workmanager
9090 Workmanager().initialize(
9191 callbackDispatcher,
92- isInDebugMode: true, // Shows notifications when tasks run
92+ isInDebugMode: true,
9393 );
9494
9595 runApp(MyApp());
Original file line number Diff line number Diff line change @@ -73,19 +73,18 @@ Future<bool> _uploadFile(Map<String, dynamic> inputData) async {
7373 }
7474
7575 // Create multipart request
76- final request = http.MultipartRequest(
77- 'POST',
78- Uri.parse('https://api.yourapp.com/upload'),
79- );
76+ final uri = Uri.parse('https://api.yourapp.com/upload');
77+ final request = http.MultipartRequest('POST', uri);
8078
81- request.headers['Authorization'] = 'Bearer YOUR_TOKEN';
82- request.fields.addAll(metadata.map((k, v) => MapEntry(k, v.toString())));
79+ request.headers['Authorization'] = 'Bearer TOKEN';
80+ request.fields.addAll(
81+ metadata.map((k, v) => MapEntry(k, v.toString()))
82+ );
8383
84- final multipartFile = await http.MultipartFile.fromPath(
85- 'file',
86- filePath,
84+ final file = await http.MultipartFile.fromPath(
85+ 'file', filePath
8786 );
88- request.files.add(multipartFile );
87+ request.files.add(file );
8988
9089 final response = await request.send().timeout(Duration(minutes: 5));
9190
You can’t perform that action at this time.
0 commit comments