Flutter 健康包在 ios 上没有返回实时数据,我必须重新打开应用程序或必须在我的应用程序和 ios 健康应用程序之间切换以进行更新

问题描述 投票:0回答:0

我每秒都在计时器中调用健康包,但它没有更新从 ios 健康工具包中获取的步数值我必须重新打开应用程序或在 ios 健康应用程序和我的应用程序之间切换

Timer.periodic(const Duration(seconds: 1), (timer) async {
todaySteps.value = await GoogleFitController.getSteps() ?? 0;
});

static Future<int?> getSteps() async {
HealthFactory health = HealthFactory();
int? steps;

var now = DateTime.now();

var midnight = DateTime(now.year, now.month, now.day, 0);
try {
  steps = await health.getTotalStepsInInterval(midnight, now);
} catch (e) {
  print("steps error ====== ${e.toString()}");
}
print("steps from google fit foreground ===== = == = = === $steps");
return steps;

}

它正在工作但不是实时更新 所有权限已授予

flutter flutter-dependencies healthkit google-fit flutter-health
© www.soinside.com 2019 - 2024. All rights reserved.