StasDoskalenko / react-native-google-fit

A React Native bridge module for interacting with Google Fit
MIT License
333 stars 209 forks source link

passing callback to `observeSteps` causes crash #328

Open 256hz opened 1 year ago

256hz commented 1 year ago

Hi there,

I would like to periodically (every ~15 min) get step count while the app is backgrounded. Is that possible with observeSteps?

I was hoping to test this, but the following line causes the app to crash:

GoogleFit.observeSteps((isError, result) => console.log({ isError, result });

When I look at the code for observeSteps, it looks like there are no arguments in the method signature:

    @ReactMethod
    public void observeSteps() {
        mGoogleFitManager.getStepCounter().findFitnessDataSources();
    }

Is this feature intended for use in the way I'm hoping?

RN: 69.1 react-native-google-fit: 0.18.3 (but latest version has the same code)

aboveyunhai commented 1 year ago

I am not sure how obeserveSteps can cooperate with headless Js if you want it to run in the background. Since google keeps changing the scope permission back and forth, and deprecate features, Most likely that's why it crashes. But I'm currently too busy to handle more things.

256hz commented 1 year ago

Thanks for your reply. I think it crashes because it's not set up to receive a callback. Have you been able to use observeSteps successfully?

aboveyunhai commented 1 year ago

@256hz yes for 2 years ago, because the permission request from javascript side was written by me at that moment. As far as I could remember, that function was broken at that moment due to the permission issue, I at least fixed that part of problems, and used it successfully. There are a lot of constraints from React Native & Google Fit regarding the live tracking. But a lot of codes might be obsolete and require full rewrite after Google made ton of changes since android 10

aboveyunhai commented 1 year ago

by the way, my fix was pretty immature at that time.

256hz commented 1 year ago

copy that. Feel free to close as won't fix or leave up if you want to address later!

aboveyunhai commented 1 year ago

@256hz it's fine, I would leave it open in case ppl encounter the similar issues. The problem is not solved yet regardless.