I follow the tutorial here (Code from Git Code repo here) for Xamarin building the first ios health-kit app but the permission dialog is not shown in the user's end. Both keywords NSHealthShareUsageDescription and NSHealthUpdateUsageDescription are in the info.plist. The code asking permission is
private void ValidateAuthorization ()
{
//Request / Validate that the app has permission to store heart-rate data
var heartRateId = HKQuantityTypeIdentifierKey.HeartRate;
var heartRateType = HKObjectType.GetQuantityType (heartRateId);
var typesToWrite = new NSSet (new [] { heartRateType });
//We aren't reading any data for this sample
var typesToRead = new NSSet ();
healthKitStore.RequestAuthorizationToShare (
typesToWrite,
typesToRead,
ReactToHealthCarePermissions);
}
If I run the app on iOS simulator, the output reports "Missing com.apple.developer.healthkit entitlement" error. I have enabled the HealthKit permission in the Entitlements.plist file and selected the option accordingly.
HKWork[935:10236] [default] connection error: Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.} Thread started: #2 HKWork[935:10236] [auth] Failed to determine authorization status: Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.} HKWork[935:10241] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x60000167c9a0> F8BB1C28-BAE8-11D6-9C31-00039315CD46
Any amount of help would be appreciated.
CodePudding user response:
I found my problem is: at Project Options->iOS Bundle signing, I need to configure both the platform of iPhoneSimulator and the platform of iPhone (select the dropdown menu to configure both). Both the signing identity and provisioning profile can't be automatic. The custom Entitlements needs to include Entitlemets.plist. I didn't set under the platform of iPhone. This change enables poping up permission page when simulating on iPhone, but not on the simulator.
Meanwhile, in Entitlement.pList, enabling capability of HealthKit might change the value of the key "com.apple.developer.healthkit". This might be a bug in Visual Studio and just don't manually change the value back because that will disable the healthkit capability.