NSInvalidArgumentException Reason: Authorization to share the following types is disallowed: HKClinicalTypeIdentifierImmunizationRecord

We are trying to read and write HealthKit clinical record from our app(Xamarin Forms app) and we are only able to read the clinical record from Health app into our app but not able to write any new data for any clinical record on behalf of the user into Health app.

Getting exception Authorization error message while request the Writing permission for Health app.

Exception Message: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: Authorization to share the following types is disallowed: HKClinicalTypeIdentifierImmunizationRecord

Please look into that and provide the solution, how we can write any new data for any clinical record into Health app.

We are waiting for your response as soon as possible.

Note: We have added all configuration related to access and write clinical record in our project and Apple

Source Code:

NSSet DataTypesToWrite
{
	get
	{
		return NSSet.MakeNSObjectSet<HKSampleType>(new HKSampleType[]
		{
			HKObjectType.GetClinicalType(HKClinicalTypeIdentifier.ImmunizationRecord)
		});
	}
}

NSSet DataTypesToRead
{
	get
	{
		return NSSet.MakeNSObjectSet<HKSampleType>(new HKSampleType[]
		{
			HKObjectType.GetClinicalType(HKClinicalTypeIdentifier.ImmunizationRecord)
		});
	}
}

public void GetHealthPermission(Action<bool,string> completion)
{
	try
	{
		if (HKHealthStore.IsHealthDataAvailable)
		{
			HealthStore = new HKHealthStore();
			HealthStore.RequestAuthorizationToShare(DataTypesToWrite, DataTypesToRead, (bool authorized, NSError error) =>
			{
				if (authorized)
				{

				}
				completion(authorized,Convert.ToString(error));
			});
		}
		else
		{
			completion(false, "Health data is not available.");
		}
	}
	catch (Exception ex)
	{
		completion(false,ex.Message);
	}
}

Getting Error on below line

HealthStore.RequestAuthorizationToShare(DataTypesToWrite, DataTypesToRead, (bool authorized, NSError error) =>
Accepted Answer

Clinical records can only be read, they cannot be written. Please see here for details: https://developer.apple.com/documentation/healthkit/samples/accessing_health_records

We also have a WWDC talk from 2018 about the clinical records API here: https://developer.apple.com/videos/play/wwdc2018/706/

Hope this helps!

NSInvalidArgumentException Reason: Authorization to share the following types is disallowed: HKClinicalTypeIdentifierImmunizationRecord
 
 
Q