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:
I believed it could work precisely because the Simulator would, nevertheless it doesn’t.