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

asynchronous register to data type #94

Open
ghost opened this issue Jan 11, 2018 · 4 comments
Open

asynchronous register to data type #94

ghost opened this issue Jan 11, 2018 · 4 comments
Labels
enhancement feature request

Comments

@ghost
Copy link

ghost commented Jan 11, 2018

whenever a new sample of a certain data type is available, wakes up the app.

For HK: see Telerik's monitorSampleType (which relies on this).

For GF, it could be done through registerDataUpdateListener of HistoryApi

@ghost ghost added enhancement feature request help wanted I am not sure I can solve this, help needed! labels Jan 11, 2018
@ghost ghost changed the title add register to data type asynchronous register to data type Jan 11, 2018
@petemcwilliams
Copy link

Thinking about helping out with this, we were interested in finding a way to synchronise health data to our servers from the background.

I'll start by looking at IOS.

@dariosalvi78
Copy link
Owner

dariosalvi78 commented Jan 16, 2018

Background in Cordova is quite challenging. There are ways, but they are not perfect.
One way would be registering to data updates with the means explained above, and, as soon as the app starts, make it go to background mode. I haven't tried it, but I suppose that the user would see it.

You can always write a plugin that implements the specific logic you need, but it'll be native, not JS.

Anyway, please share your findings !

@petemcwilliams
Copy link

petemcwilliams commented Jan 17, 2018

It looked like it should be possible with HKObserverQuery and enablebackgrounddelivery unfortunately I do not understand objective-c enough or the cordova structure to progress this. I think queries would need to be setup in pluginInitialize but how to keep it a generic plugin at that stage. So I'm not going to look into this any further for the moment.

EddyVerbruggen#92 details the current limitation.

I was using the following code to test it out in your health.js.

Health.prototype.monitor = function (opts, onSuccess, onError) {
  if ((opts.dataType !== 'steps') && (opts.dataType !== 'activity') &&
  (opts.dataType !== 'workouts')) {
    // unsupported datatype
    onError('Datatype ' + opts.dataType + ' not supported in monitor');
    return;
  }

  if (opts.dataType == 'workouts' || opts.dataType == 'activity') {
    opts.sampleType = 'workoutType';
  } else {
    opts.sampleType = dataTypes[opts.dataType];
  }
  
  console.log(opts);

  window.plugins.healthkit.monitorSampleType(opts,
    function (value) {
      // this gets called when a new sample is available (can then be fetched by a different function)
      console.log(opts.dataType, " things happend: ", value);
    },
    onError)
}

@dariosalvi78
Copy link
Owner

even if you manage to make the HKObserverQuery work, you will probably have to bring the app to foreground anyway so that the webview could run the JS code.
I haven't found any example online regarding iOS or Android running JS code in background (eg in an Android service).

One way could be creating a plugin that executes a generic JS engine in background. Both Android and iOS have JS engines (like this or this) but that's the goal for a completely separate plugin (a very needed one indeed !).

@ghost ghost removed the help wanted I am not sure I can solve this, help needed! label May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature request
Projects
None yet
Development

No branches or pull requests

2 participants