kvs-coder / health_kit_reporter

A Flutter wrapper for the HealthKitReporter library
https://pub.dev/packages/health_kit_reporter
MIT License
38 stars 38 forks source link

Identifier unknown error #62

Open maxbeech opened 1 year ago

maxbeech commented 1 year ago

Thanks so much for the awesome package!

I'd hugely appreciate your help with this please.

I am getting the error PlatformException(<health_kit_reporter.SwiftHealthKitReporterPlugin: 0x283a82330>, Error in parsing quantity type, Identifier unknown: HKQuantityTypeIdentifierAppleSleepingWristTemperature, null) when I try to run the code:

// Authorise usage of all data
final List<String> readTypes = <String>[];
readTypes.addAll(QuantityType.values.map((e) => e.identifier));
final writeTypes = <String>[];
authorized = await HealthKitReporter.requestAuthorization(readTypes, writeTypes);

// Prepare to get data
List<QuantityType> typesToGet = [];
for (final QuantityType e in QuantityType.values) {
   final QuantityType? type = QuantityTypeFactory.tryFrom(e.identifier);
   if (type != null) {
      typesToGet.add(type);
   }
}
List<PreferredUnit> preferredUnits = await HealthKitReporter.preferredUnits(typesToGet);

If I manually remove this value from the list before running the final preferredUnits(typesToGet) line, I then get the error with other types such as runningStrideLength, runningVerticalOscillation and runningGroundContactTime.

I wonder if perhaps it is because I don't have an Apple Watch so don't have any data from that - if so though, some guidance on how to handle this would be much appreciated.

Thank you!

Famous-guy commented 9 months ago

It seems like you're encountering an error related to parsing quantity types when using the health_kit_reporter plugin in your Flutter app. The error message indicates that the identifier HKQuantityTypeIdentifierAppleSleepingWristTemperature is unknown or unsupported.

Here are a few steps you can take to troubleshoot and potentially resolve this issue:

Check Identifier Compatibility: Verify that the quantity type identifiers you're using are supported by the HealthKit framework on iOS. Some identifiers may be specific to certain types of data or device capabilities, such as Apple Watch sensors. Refer to the official Apple HealthKit documentation to ensure that the identifiers you're using are valid and supported.

Handle Unsupported Types: If certain quantity types are not available or supported on the user's device (e.g., because they don't have an Apple Watch), you'll need to handle these cases gracefully in your code. This may involve excluding unsupported types from your queries or providing alternative functionality for users without access to certain types of data.

Error Handling: Implement proper error handling in your Flutter code to catch and handle platform exceptions like the one you're encountering. This can help provide more informative error messages to users and aid in debugging issues related to health data retrieval.

Testing: Test your app on devices with different configurations, including those with and without Apple Watches, to see if the issue persists across different scenarios. This can help identify whether the problem is specific to certain types of data or device setups.

Plugin Updates: Ensure that you're using the latest version of the health_kit_reporter plugin, as newer versions may include bug fixes or updates related to quantity type handling and compatibility.

By carefully reviewing your code, verifying quantity type identifiers, handling unsupported types gracefully, implementing error handling, and testing across different device configurations, you should be able to address the issue with parsing quantity types in your Flutter app. If the problem persists, consider reaching out to the plugin's developers or the Flutter community for further assistance and guidance.

Thanks so much for the awesome package!

I'd hugely appreciate your help with this please.

I am getting the error PlatformException(<health_kit_reporter.SwiftHealthKitReporterPlugin: 0x283a82330>, Error in parsing quantity type, Identifier unknown: HKQuantityTypeIdentifierAppleSleepingWristTemperature, null) when I try to run the code:

// Authorise usage of all data
final List<String> readTypes = <String>[];
readTypes.addAll(QuantityType.values.map((e) => e.identifier));
final writeTypes = <String>[];
authorized = await HealthKitReporter.requestAuthorization(readTypes, writeTypes);

// Prepare to get data
List<QuantityType> typesToGet = [];
for (final QuantityType e in QuantityType.values) {
   final QuantityType? type = QuantityTypeFactory.tryFrom(e.identifier);
   if (type != null) {
      typesToGet.add(type);
   }
}
List<PreferredUnit> preferredUnits = await HealthKitReporter.preferredUnits(typesToGet);

If I manually remove this value from the list before running the final preferredUnits(typesToGet) line, I then get the error with other types such as runningStrideLength, runningVerticalOscillation and runningGroundContactTime.

I wonder if perhaps it is because I don't have an Apple Watch so don't have any data from that - if so though, some guidance on how to handle this would be much appreciated.

Thank you!