Skip to content

Commit

Permalink
[HealthKit] Add support for xcode13 beta4. (#12184)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel-macaque authored Jul 29, 2021
1 parent 9eba3b4 commit dab0f2e
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 70 deletions.
47 changes: 47 additions & 0 deletions src/HealthKit/HKAppleWalkingSteadiness.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Runtime.InteropServices;
using ObjCRuntime;
using Foundation;
using HKQuantityRef = System.IntPtr;
using NSErrorRef = System.IntPtr;

#nullable enable

namespace HealthKit {

[Watch (8,0), iOS (15,0)]
public static class HKAppleWalkingSteadiness
{

[DllImport (Constants.HealthKitLibrary)]
static extern bool HKAppleWalkingSteadinessClassificationForQuantity (HKQuantityRef value, out nint classificationOut, out NSErrorRef errorOut);

public static bool TryGetClassification (HKQuantity value, out HKAppleWalkingSteadinessClassification? classification, out NSError? error)
{
if (value == null)
throw new ArgumentNullException (nameof (value));
classification = null;
error = null;
if (HKAppleWalkingSteadinessClassificationForQuantity (value.GetHandle (), out var classificationOut, out var errorPtr)) {
classification = (HKAppleWalkingSteadinessClassification) (long) classificationOut;
error = Runtime.GetNSObject<NSError> (errorPtr, false);
return true;
}
return false;

}

[DllImport (Constants.HealthKitLibrary)]
static extern HKQuantityRef HKAppleWalkingSteadinessMinimumQuantityForClassification (nint classification);

public static HKQuantity GetMinimumQuantity (HKAppleWalkingSteadinessClassification classification)
=> Runtime.GetNSObject<HKQuantity> (HKAppleWalkingSteadinessMinimumQuantityForClassification ((nint) (long) classification), false);

[DllImport (Constants.HealthKitLibrary)]
static extern HKQuantityRef HKAppleWalkingSteadinessMaximumQuantityForClassification (nint classification);

public static HKQuantity GetMaximumQuantity (HKAppleWalkingSteadinessClassification classification)
=> Runtime.GetNSObject<HKQuantity> (HKAppleWalkingSteadinessMaximumQuantityForClassification ((nint) (long) classification), false);
}

}
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ HEALTHKIT_API_SOURCES = \

HEALTHKIT_SOURCES = \
HealthKit/EnumsCompat.cs \
HealthKit/HKAppleWalkingSteadiness.cs \
HealthKit/HKAnchoredObjectQuery.cs \
HealthKit/HKObjectType.cs \
HealthKit/HKObsolete.cs \
Expand Down
170 changes: 167 additions & 3 deletions src/healthkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,39 @@ public enum HKCategoryValueHeadphoneAudioExposureEvent : long {
SevenDayLimit = 1,
}

[Watch (8,0), iOS (15,0)]
[Native]
public enum HKAppleWalkingSteadinessClassification : long {
Ok = 1,
Low,
VeryLow,
}

[Watch (8,0), iOS (15,0)]
[Native]
public enum HKCategoryValueAppleWalkingSteadinessEvent : long {
InitialLow = 1,
InitialVeryLow = 2,
RepeatLow = 3,
RepeatVeryLow = 4,
}

[Watch (8,0), iOS (15,0)]
[Native]
public enum HKCategoryValuePregnancyTestResult : long {
Negative = 1,
Positive,
Indeterminate,
}

[Watch (8,0), iOS (15,0)]
[Native]
public enum HKCategoryValueProgesteroneTestResult : long {
Negative = 1,
Positive,
Indeterminate,
}

delegate void HKAnchoredObjectResultHandler2 (HKAnchoredObjectQuery query, HKSample[] results, nuint newAnchor, NSError error);

[Obsolete ("Use HKAnchoredObjectResultHandler2 instead")]
Expand Down Expand Up @@ -122,6 +155,10 @@ interface HKAnchoredObjectQuery {
[Export ("initWithType:predicate:anchor:limit:resultsHandler:")]
IntPtr Constructor (HKSampleType type, [NullAllowed] NSPredicate predicate, [NullAllowed] HKQueryAnchor anchor, nuint limit, HKAnchoredObjectUpdateHandler handler);

[Watch (8,0), iOS (15,0)]
[Export ("initWithQueryDescriptors:anchor:limit:resultsHandler:")]
IntPtr Constructor (HKQueryDescriptor[] queryDescriptors, [NullAllowed] HKQueryAnchor anchor, nint limit, HKAnchoredObjectUpdateHandler resultsHandler);

[iOS (9,0)]
[NullAllowed, Export ("updateHandler", ArgumentSemantic.Copy)]
HKAnchoredObjectUpdateHandler UpdateHandler { get; set; }
Expand Down Expand Up @@ -512,17 +549,17 @@ interface HKHealthStore {
[Export ("bloodTypeWithError:")]
HKBloodTypeObject GetBloodType (out NSError error);

[NoWatch]
[Watch (8,0)]
[Async]
[Export ("enableBackgroundDeliveryForType:frequency:withCompletion:")]
void EnableBackgroundDelivery (HKObjectType type, HKUpdateFrequency frequency, Action<bool, NSError> completion);

[NoWatch]
[Watch (8,0)]
[Async]
[Export ("disableBackgroundDeliveryForType:withCompletion:")]
void DisableBackgroundDelivery (HKObjectType type, Action<bool, NSError> completion);

[NoWatch]
[Watch (8,0)]
[Async]
[Export ("disableAllBackgroundDeliveryWithCompletion:")]
void DisableAllBackgroundDelivery (Action<bool, NSError> completion);
Expand Down Expand Up @@ -591,6 +628,11 @@ interface HKHealthStore {
[Watch (5,0), NoiOS]
[Export ("recoverActiveWorkoutSessionWithCompletion:")]
void RecoverActiveWorkoutSession (HKHealthStoreRecoverActiveWorkoutSessionHandler completion);

[Async]
[Watch (8,0), iOS (15,0)]
[Export ("recalibrateEstimatesForSampleType:atDate:completion:")]
void RecalibrateEstimates (HKSampleType sampleType, NSDate date, Action<bool, NSError> completion);
}

delegate void HKStoreSampleAddedCallback (bool success, NSError error);
Expand Down Expand Up @@ -957,6 +999,10 @@ interface HKMetadataKey {
[Watch (7, 2), iOS (14, 3)]
[Field ("HKMetadataKeyLowCardioFitnessEventThreshold")]
NSString LowCardioFitnessEventThreshold { get; }

[Watch (8, 0), iOS (15, 0)]
[Field ("HKMetadataKeyDateOfEarliestDataUsedForEstimate")]
NSString DateOfEarliestDataUsedForEstimate { get;}
}

[Watch (2,0)]
Expand Down Expand Up @@ -1126,6 +1172,10 @@ interface HKSampleType {
[iOS (13,0), Watch (6,0)]
[Export ("minimumAllowedDuration")]
double MinimumAllowedDuration { get; }

[Watch (8, 0), iOS (15, 0)]
[Export ("allowsRecalibrationForEstimates")]
bool AllowsRecalibrationForEstimates { get; }
}

[Watch (5,0)]
Expand Down Expand Up @@ -1166,6 +1216,9 @@ interface HKQuantityType {

delegate void HKObserverQueryUpdateHandler (HKObserverQuery query, [BlockCallback] Action completion, NSError error);

[Watch (8,0), iOS (15,0)]
delegate void HKObserverQueryDescriptorUpdateHandler (HKObserverQuery query, NSSet<HKSampleType> samples, [BlockCallback] Action completion, NSError error);

[Watch (2,0)]
[iOS (8,0)]
[BaseType (typeof (HKQuery))]
Expand All @@ -1176,6 +1229,10 @@ interface HKQuantityType {
interface HKObserverQuery {
[Export ("initWithSampleType:predicate:updateHandler:")]
IntPtr Constructor (HKSampleType sampleType, [NullAllowed] NSPredicate predicate, HKObserverQueryUpdateHandler updateHandler);

[Watch (8,0), iOS (15,0)]
[Export ("initWithQueryDescriptors:updateHandler:")]
IntPtr Constructor (HKQueryDescriptor[] queryDescriptors, HKObserverQueryDescriptorUpdateHandler updateHandler);
}

[Watch (2,0)]
Expand Down Expand Up @@ -1393,6 +1450,12 @@ interface HKQuery {
[Static]
[Export ("predicateForElectrocardiogramsWithSymptomsStatus:")]
NSPredicate GetPredicateForElectrocardiograms (HKElectrocardiogramSymptomsStatus symptomsStatus);

// @interface HKVerifiableClinicalRecordPredicates (HKQuery)
[iOS (15,0), Watch (8,0)]
[Static]
[Export ("predicateForVerifiableClinicalRecordsWithRelevantDateWithinDateInterval:")]
NSPredicate GetPredicateForVerifiableClinicalRecords (NSDateInterval dateInterval);
}

[Watch (2,0)]
Expand Down Expand Up @@ -1442,6 +1505,14 @@ interface HKSampleQuery {

[Export ("initWithSampleType:predicate:limit:sortDescriptors:resultsHandler:")]
IntPtr Constructor (HKSampleType sampleType, [NullAllowed] NSPredicate predicate, nuint limit, [NullAllowed] NSSortDescriptor[] sortDescriptors, HKSampleQueryResultsHandler resultsHandler);

[Watch (8,0), iOS (15,0)]
[Export ("initWithQueryDescriptors:limit:resultsHandler:")]
IntPtr Constructor (HKQueryDescriptor[] queryDescriptors, nint limit, HKSampleQueryResultsHandler resultsHandler);

[Watch (8,0), iOS (15,0)]
[Export ("initWithQueryDescriptors:limit:sortDescriptors:resultsHandler:")]
IntPtr Constructor (HKQueryDescriptor[] queryDescriptors, nint limit, NSSortDescriptor[] sortDescriptors, HKSampleQueryResultsHandler resultsHandler);
}

[Watch (2,0)]
Expand Down Expand Up @@ -1908,6 +1979,14 @@ enum HKQuantityTypeIdentifier {
[Watch (7,4)][iOS (14,5)]
[Field ("HKQuantityTypeIdentifierAppleMoveTime")]
AppleMoveTime,

[Watch (8, 0), iOS (15, 0)]
[Field ("HKQuantityTypeIdentifierAppleWalkingSteadiness")]
AppleWalkingSteadiness,

[Watch (8, 0), iOS (15, 0)]
[Field ("HKQuantityTypeIdentifierNumberOfAlcoholicBeverages")]
NumberOfAlcoholicBeverages,
}

[Watch (2,0)]
Expand Down Expand Up @@ -2167,6 +2246,18 @@ enum HKCategoryTypeIdentifier
[Watch (7, 2), iOS (14, 3)]
[Field ("HKCategoryTypeIdentifierLowCardioFitnessEvent")]
LowCardioFitnessEvent,

[Watch (8, 0), iOS (15, 0)]
[Field ("HKCategoryTypeIdentifierAppleWalkingSteadinessEvent")]
AppleWalkingSteadinessEvent,

[Watch (8, 0), iOS (15, 0)]
[Field ("HKCategoryTypeIdentifierPregnancyTestResult")]
PregnancyTestResult,

[Watch (8, 0), iOS (15, 0)]
[Field ("HKCategoryTypeIdentifierProgesteroneTestResult")]
ProgesteroneTestResult,
}

[Watch (2,0)]
Expand Down Expand Up @@ -3554,4 +3645,77 @@ enum HKCategoryValueContraceptive : long {
enum HKCategoryValueLowCardioFitnessEvent : long {
LowFitness = 1,
}

[Watch (8,0), iOS (15,0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface HKQueryDescriptor : NSCopying, NSSecureCoding
{
[Export ("sampleType", ArgumentSemantic.Copy)]
HKSampleType SampleType { get; }

[NullAllowed, Export ("predicate", ArgumentSemantic.Copy)]
NSPredicate Predicate { get; }

[Export ("initWithSampleType:predicate:")]
[DesignatedInitializer]
IntPtr Constructor (HKSampleType sampleType, [NullAllowed] NSPredicate predicate);
}

[NoWatch, iOS (15,0)]
[BaseType (typeof (HKSample))]
[DisableDefaultCtor]
interface HKVerifiableClinicalRecord
{
[Export ("recordTypes", ArgumentSemantic.Copy)]
string[] RecordTypes { get; }

[Export ("issuerIdentifier")]
string IssuerIdentifier { get; }

[Export ("subject", ArgumentSemantic.Copy)]
HKVerifiableClinicalRecordSubject Subject { get; }

[Export ("issuedDate", ArgumentSemantic.Copy)]
NSDate IssuedDate { get; }

[Export ("relevantDate", ArgumentSemantic.Copy)]
NSDate RelevantDate { get; }

[NullAllowed, Export ("expirationDate", ArgumentSemantic.Copy)]
NSDate ExpirationDate { get; }

[Export ("itemNames", ArgumentSemantic.Copy)]
string[] ItemNames { get; }

[Export ("JWSRepresentation", ArgumentSemantic.Copy)]
NSData JwsRepresentation { get; }
}

delegate void HKVerifiableClinicalRecordQueryResultHandler (HKVerifiableClinicalRecordQuery query, NSArray<HKVerifiableClinicalRecord> records, NSError error);

[NoWatch, iOS (15,0)]
[BaseType (typeof (HKQuery))]
[DisableDefaultCtor]
interface HKVerifiableClinicalRecordQuery
{
[Export ("recordTypes", ArgumentSemantic.Copy)]
string[] RecordTypes { get; }

[Export ("initWithRecordTypes:predicate:resultsHandler:")]
IntPtr Constructor (string[] recordTypes, [NullAllowed] NSPredicate predicate, HKVerifiableClinicalRecordQueryResultHandler handler);
}

[NoWatch, iOS (15,0)]
[BaseType (typeof(NSObject))]
[DisableDefaultCtor]
interface HKVerifiableClinicalRecordSubject : NSSecureCoding, NSCopying
{
[Export ("fullName")]
string FullName { get; }

[NullAllowed, Export ("dateOfBirthComponents", ArgumentSemantic.Copy)]
NSDateComponents DateOfBirthComponents { get; }
}

}
3 changes: 3 additions & 0 deletions tests/introspection/ApiProtocolTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ protected virtual bool Skip (Type type, string protocolName)
case "HMCharacteristicMetadata":
case "HMAccessoryCategory":
return true;
// Xcode 13
case "HKVerifiableClinicalRecord":
return true;
}
break;
case "NSMutableCopying":
Expand Down
8 changes: 8 additions & 0 deletions tests/introspection/ApiSelectorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ protected virtual bool Skip (Type type, string selectorName)
break;
}
break;
case "HKQuery":
switch (selectorName) {
case "predicateForVerifiableClinicalRecordsWithRelevantDateWithinDateInterval:": // not available in the sim
if (Runtime.Arch == Arch.SIMULATOR) // not available in the sim
return true;
break;
}
break;
#endif
case "WKPreferences":
switch (selectorName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Unit tests for HKCategoryTypeIdentifier
//
// Authors:
Expand Down
42 changes: 42 additions & 0 deletions tests/monotouch-test/HealthKit/HKAppleWalkingSteadinessTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#if HAS_HEALTHKIT

using System;

using Foundation;
using HealthKit;
using UIKit;
using NUnit.Framework;

namespace MonoTouchFixtures.HealthKit {

[TestFixture]
[Preserve (AllMembers = true)]
public class HKAppleWalkingSteadinessTest {

[SetUp]
public void SetUp ()
{
TestRuntime.AssertXcodeVersion (13, 0);
}

[Test]
public void TryGetClassificationTest ()
{
var max = HKAppleWalkingSteadiness.GetMaximumQuantity (HKAppleWalkingSteadinessClassification.Ok);
Assert.True (HKAppleWalkingSteadiness.TryGetClassification (max, out var classification, out var error));
Assert.Null (error, "error");
Assert.AreEqual (classification, HKAppleWalkingSteadinessClassification.Ok, "classification");
}

[Test]
public void GetMinimumQuantityTest ()
=> Assert.NotNull (HKAppleWalkingSteadiness.GetMinimumQuantity (HKAppleWalkingSteadinessClassification.Ok));

[Test]
public void GetMaximumQuantityTest ()
=> Assert.NotNull (HKAppleWalkingSteadiness.GetMaximumQuantity (HKAppleWalkingSteadinessClassification.Ok));
}
}

#endif // HAS_HEALTHKIT

Loading

6 comments on commit dab0f2e

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff

API & Generator diff

ℹ️ API Diff (from PR only) (please review changes)
ℹ️ Generator Diff (please review changes)

Packages generated

View packages

Test results

7 tests failed, 217 tests passed.

Failed tests

  • xammac tests/Mac Modern/Debug: Failed (Test run failed.
    Tests run: 2463 Passed: 2411 Inconclusive: 13 Failed: 1 Ignored: 51)
  • xammac tests/Mac Modern/Debug (all optimizations): Failed (Test run failed.
    Tests run: 2460 Passed: 2408 Inconclusive: 13 Failed: 1 Ignored: 51)
  • xammac tests/Mac Modern/Release: Failed (Test run failed.
    Tests run: 2460 Passed: 2407 Inconclusive: 13 Failed: 1 Ignored: 52)
  • xammac tests/Mac Modern/Release (all optimizations): Failed (Test run failed.
    Tests run: 2460 Passed: 2406 Inconclusive: 13 Failed: 1 Ignored: 53)
  • monotouch-test/iOS Unified 32-bits - simulator/Debug: Failed
  • monotouch-test/tvOS - simulator/Debug (static registrar) [dotnet]: Failed
  • Documentation/All: Failed

Pipeline on Agent XAMBOT-1035.BigSur'
[HealthKit] Add support for xcode13 beta4. (#12184)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests tvOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[HealthKit] Add support for xcode13 beta4. (#12184)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests iOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[HealthKit] Add support for xcode13 beta4. (#12184)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Tests failed on macOS M1 - Mac Big Sur (11.5) ❌

Tests failed on M1 - Mac Big Sur (11.5).

Failed tests are:

  • xammac_tests

Pipeline on Agent
[HealthKit] Add support for xcode13 beta4. (#12184)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Tests passed on macOS Mac Mojave (10.14) ✅

Tests passed

All tests on macOS X Mac Mojave (10.14) passed.

Pipeline on Agent
[HealthKit] Add support for xcode13 beta4. (#12184)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Tests passed on macOS Mac High Sierra (10.13) ✅

Tests passed

All tests on macOS X Mac High Sierra (10.13) passed.

Pipeline on Agent
[HealthKit] Add support for xcode13 beta4. (#12184)

Please sign in to comment.