Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Saving user defined time

Hi guys,

I am developing an app that reminds users to take medication before they go to sleep and tracks if they have taken the medication in the required dosage period. I am very new to developing apps for FitBits, though I do have some knowledge of web development that comes in very handy.

 

Up till now, I have followed examples to make an app that displays the time, and shows a message if the time is greater than or equal to a hard coded value as shown in the below snippet;

if(preferences.clockDisplay == "12h"){
     if(hours == 1 && hrm <= 60)
       checkLabel.text = "Take your meds yet?";
   }else{
     if(hours >= 23 && mins > 36 && hrm <= 60)
       checkLabel.text = "Take your meds yet?";
  }

 However, I would like to enhance the app further by replacing the hard coded values in the nested IF statements to values of user defined prerequisites, set within the companion app.

I almost understand how the companion side works with the app etc, but I do not really understand how I can read the user defined values and use them in the IF statements (or anywhere else for that matter).

Would anyone here be able to help me with this?

 

I'd also like to use someway of determining if the current time is before or after the predicted sunset time as per a Google search result, and whether the heart rate is close to resting for some time. But I am sure I will figure this out in due course.

 

 

Best Answer
0 Votes
1 REPLY 1

1. You need to define your options using the Settings API

2. When a user configures them, they get persisted in settingsStorage on the phone

3. The companion API can detect when these values are saved, then you can send them to the device using the Messaging API.

4. The device can listen for those values and save them on device

5. Then you can use them in your IF statement.

 

https://dev.fitbit.com/build/guides/settings/

https://dev.fitbit.com/build/guides/communications/messaging/

 

It's a bit fiddly, but there's a full example here:

https://github.com/fitbit/sdk-moment

 

1. & 2. https://github.com/Fitbit/sdk-moment/blob/master/settings/index.jsx

3. https://github.com/Fitbit/sdk-moment/blob/master/companion/simple/companion-settings.js

4. https://github.com/Fitbit/sdk-moment/blob/master/app/simple/device-settings.js

5. https://github.com/Fitbit/sdk-moment/blob/master/app/index.js#L52

Best Answer
0 Votes