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 acquired it related to the undertaking however there may be one drawback. I’ve a function that collects and shows well being options from the consumer’s native ‘Well being’ app. It labored on the iOS simulator after I first began testing my app but it surely would not appear to gather it after I use the app on my precise iPhone. Furthermore, it asks for permissions on the simulator but it surely 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 = [];
Checklist<HealthDataPoint> healthData =
await well being.getHealthDataFromTypes(midnight, now, [types[0]]);
await well being.requestAuthorization(varieties, permissions: permissions);
if (healthData.isEmpty) {
showBanner('No information out there. 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 if you happen to any extra info. Thanks as soon as once more.
Listed below are screenshots of my iPhone’s permissions too:
I assumed it might work precisely because the Simulator would, but it surely doesn’t.