flutter_workmanager icon indicating copy to clipboard operation
flutter_workmanager copied to clipboard

feature/handle-input-data-background-processing-ios

Open EArminjon2 opened this issue 3 years ago • 1 comments

Based on 0.5.0-dev.8 Actual behavior make inputData always null on iOS background processing. This PR fix that.

EArminjon2 avatar Jun 03 '22 14:06 EArminjon2

What if you have multiple background workers running, won't the input data be overridden for each? Or, inputData from task A is available on task B (which is unintended)

ened avatar Sep 03 '22 08:09 ened

What if you have multiple background workers running, won't the input data be overridden for each? Or, inputData from task A is available on task B (which is unintended)

I do not think so if the uniqueName is different or the work policy is set to ExistingWorkPolicy.append; although, I have yet to test this yet.

AdamBridges avatar Sep 26 '22 18:09 AdamBridges

@AdamBridges what did you find out? I would be looking for storing input data in a hash table, specific to the supplied uniqueTaskName.

ened avatar Oct 23 '22 11:10 ened

@AdamBridges what did you find out? I would be looking for storing input data in a hash table, specific to the supplied uniqueTaskName.

Pardon the delay: I've been trying to test things out on iOS but I can't escape this error on 0.5.1 before I try this PR:

flutter: PlatformException(unhandledMethod("registerOneOffTask") error, Unhandled method registerOneOffTask, null, null)
flutter: 
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
<asynchronous suspension>
#2      Workmanager.registerOneOffTask (package:workmanager/src/workmanager.dart:192:7)
<asynchronous suspension>

@ened Any ideas what's going on here?

Here's what I'm calling and doing so on a real iphone:

inputData ??= {};
inputData.addAll({
      taskKey : uniqueTaskName,
      tagKey : retryProcessTag
    });
await Workmanager().registerOneOffTask(
        "task-identifier",
        "retryProcess", // Ignored on iOS
        initialDelay: Duration(minutes: 30),
        constraints: Constraints(
          // connected or metered mark the task as requiring internet
          networkType: NetworkType.connected,
          // require external power
          requiresCharging: true,
        ),
        inputData: inputData // fully supported
    );

EDIT: Are OneOffTasks only available for devices with iOS 13+?

AdamBridges avatar Nov 06 '22 22:11 AdamBridges

@ened Okay, I tested with an external device using iOS 15.6 with this PR and with 0.5.1:

PR works when testing app in the foreground. Could not test in the background because the command hangs when trying to test BGTaskScheduler until the app is brought to the foreground.

0.5.1 always returns null inputData despite the README docs claiming it's fully supported.

AdamBridges avatar Nov 14 '22 22:11 AdamBridges

@AdamBridges what did you find out? I would be looking for storing input data in a hash table, specific to the supplied uniqueTaskName.

Pardon the delay: I've been trying to test things out on iOS but I can't escape this error on 0.5.1 before I try this PR:

flutter: PlatformException(unhandledMethod("registerOneOffTask") error, Unhandled method registerOneOffTask, null, null)
flutter: 
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
<asynchronous suspension>
#2      Workmanager.registerOneOffTask (package:workmanager/src/workmanager.dart:192:7)
<asynchronous suspension>

@ened Any ideas what's going on here?

Here's what I'm calling and doing so on a real iphone:

inputData ??= {};
inputData.addAll({
      taskKey : uniqueTaskName,
      tagKey : retryProcessTag
    });
await Workmanager().registerOneOffTask(
        "task-identifier",
        "retryProcess", // Ignored on iOS
        initialDelay: Duration(minutes: 30),
        constraints: Constraints(
          // connected or metered mark the task as requiring internet
          networkType: NetworkType.connected,
          // require external power
          requiresCharging: true,
        ),
        inputData: inputData // fully supported
    );

EDIT: Are OneOffTasks only available for devices with iOS 13+?

As i wrote, this PR is based on '0.5.0-dev.8'. Are you on this version ?

EArminjon avatar Nov 15 '22 08:11 EArminjon

Yes, I have tested both. You can ignore that comment.

The one major caveat with this PR is that inputData likely gets overwritten if a different task is scheduled while one is pending because the background task key is always workmanager.background.task. However, 0.5.1 has corrected this issue so this PR should merge quite nicely and restore function to inputData.

@EArminjon @EArminjon2 Would you mind updating this PR to 0.5.1 with your changes to inputData?

AdamBridges avatar Nov 15 '22 18:11 AdamBridges

Note that this PR is failing on Android.

AdamBridges avatar Nov 22 '22 18:11 AdamBridges

Note that this PR is failing on Android.

This Pr works for 0.5.0-dev.8 and maybe an old version of flutter now....

EArminjon avatar Nov 22 '22 18:11 EArminjon

I will not update this PR. I've not the time and the skills to do it... (I'm not a native developer). The PR was enough for the version 0.5.0-dev.8 because we cannot register multiple task. It was perfect for my app. Recent version can. Maintainer should fix it's package and handle the case of this PR.

EArminjon avatar Nov 22 '22 18:11 EArminjon

The periodic register task of 15 minutes is completely working on Android but not working on iOS. I have to perform every 15 minutes task in iOS with the work manager how can I do it? Every time I get this error while registering periodic time with 15 mites in iOS. Anyone, please reply or suggest any other alternative solution to me.

Error: PlatformException(unhandledMethod("registerPeriodicTask") error, Unhandled method registerPeriodicTask, null, null)

OE-Ahmed avatar May 25 '23 07:05 OE-Ahmed

The periodic register task of 15 minutes is completely working on Android but not working on iOS. I have to perform every 15 minutes task in iOS with the work manager how can I do it? Every time I get this error while registering periodic time with 15 mites in iOS. Anyone, please reply or suggest any other alternative solution to me.

Error: PlatformException(unhandledMethod("registerPeriodicTask") error, Unhandled method registerPeriodicTask, null, null)

This PR was working with the specified package version and maybe with flutter 2.10.5.

@all As this PR is not a bug ticket, please create a dedicated one and stop polute this topic with unrelated things please

EArminjon avatar May 25 '23 11:05 EArminjon

Please give me an alternative solution, If you have any. Flutter 3.3.8 • channel stable • https://github.com/flutter/flutter.git Framework • revision 52b3dc25f6 (7 months ago) • 2022-11-09 12:09:26 +0800 Engine • revision 857bd6b74c Tools • Dart 2.18.4 • DevTools 2.15.0

Above is my flutter version.

OE-Ahmed avatar May 25 '23 13:05 OE-Ahmed

Please give me an alternative solution, If you have any. Flutter 3.3.8 • channel stable • https://github.com/flutter/flutter.git Framework • revision 52b3dc25f6 (7 months ago) • 2022-11-09 12:09:26 +0800 Engine • revision 857bd6b74c Tools • Dart 2.18.4 • DevTools 2.15.0

Above is my flutter version.

I'm not the maintainer. I'm just a dev.

I opened this PR while I was working on a project whith a particular version of this package and flutter. I can't and will not provide support for newer version :') ! I just report a bug. All questions in this PR topic are mostly out of context. PLEASE CREATE DEDICATED ISSUE...

EArminjon avatar May 25 '23 13:05 EArminjon

Why, did I create a dedicated issue? I will not create a dedicated issue. GIve me a solution first.

OE-Ahmed avatar May 25 '23 13:05 OE-Ahmed

Why, did I create a dedicated issue? I will not create a dedicated issue. GIve me a solution first.

... I'm not the maintainer and i didn't have the solution for your issue. In addition it's a PR ticket not a bug ticket, in addition your issue is not linked to the PR.

EArminjon avatar May 25 '23 13:05 EArminjon