Tuesday, December 19, 2023
HomeiOS DevelopmentWhy does the 'Well being' iOS bundle for Flutter not acquire my...

Why does the ‘Well being’ iOS bundle for Flutter not acquire my info on my precise iPhone?


I’m making an attempt to create a Well being app and I began utilizing my precise iPhone as a simulator for the app. I’ve received it linked to the challenge however there’s one downside. I’ve a characteristic that collects and shows well being options from the person’s native ‘Well being’ app. It labored on the iOS simulator after I first began testing my app nevertheless it would not appear to gather it after I use the app on my precise iPhone. Furthermore, it asks for permissions on the simulator nevertheless it would not appear to take action on my iPhone.

Right here is the related code:

var varieties = [
    HealthDataType.ACTIVE_ENERGY_BURNED,
    HealthDataType.STEPS,
  ];

  var permissions = [
    HealthDataAccess.READ,
    HealthDataAccess.READ,
  ];

void getCaloriesBurned() async {
    var now = DateTime.now();
    var midnight = DateTime(now.yr, now.month, now.day);
    var strings = [];

    Record<HealthDataPoint> healthData =
        await well being.getHealthDataFromTypes(midnight, now, [types[0]]);

    await well being.requestAuthorization(varieties, permissions: permissions);

    if (healthData.isEmpty) {
      showBanner('No information accessible. Log some energy into the Well being app!');
      return;
    }

    for (var dataPoint in healthData) {
      strings.add(dataPoint.worth.toString());
    }

    for (var string in strings) {
      caloriesBurned += double.parse(string).spherical();
    }

    await addCaloriesBurnedToFirestore(caloriesBurned);

    setState(() {
      caloriesBurned = caloriesBurned;
    });
  }

getSteps() async {
    var now = DateTime.now();
    var midnight = DateTime(now.yr, now.month, now.day);

    int? healthData = await well being.getTotalStepsInInterval(midnight, now);

    await well being.requestAuthorization(varieties, permissions: permissions);

    if (healthData != null) {
      setState(() {
        totalSteps = healthData.toDouble().spherical();
      });
      await addStepsToFirestore(totalSteps);
    } else {}
  }

@override
  void initState() {
    tremendous.initState();

    well being.requestAuthorization(varieties);
    getSteps();
    getCaloriesBurned();
    fetchPreviousSteps();
    fetchPreviousCalories();
  }

Let me know in case you any extra info. Thanks as soon as once more.

Listed here are screenshots of my iPhone’s permissions too:
enter image description here
enter image description here

I believed it could work precisely because the Simulator would, nevertheless it doesn’t.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments