HealthKit error: Missing com.apple.developer.healthkit entitlement - swift

I'm adding code for HealthKit in my iOS Swift app, but I'm getting an error:
/* Ask for permission to access the health store */
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if HKHealthStore.isHealthDataAvailable(){
healthStore.requestAuthorizationToShareTypes(typesToShare,
readTypes: typesToRead,
completion: {(succeeded: Bool, error: NSError!) in
if succeeded && error == nil{
println("Successfully received authorization")
} else {
if let theError = error{
println("Error occurred = \(theError)")
}
}
})
} else {
println("Health data is not available")
}
}
Error occurred = Error Domain=com.apple.healthkit Code=4 "Missing
com.apple.developer.healthkit entitlement." UserInfo=0x7fa748534b00
{NSLocalizedDescription=Missing com.apple.developer.healthkit
entitlement.}
How can solve this?

I spent 3 days trying to figure out what was the problem. I found the solution with those steps:
First go to the project (As I show in the image)
Open projects and target lists
Select nameApp WatchKit Extension
Go to Capabilities tab, press on in Health Kit and voila... it is working for me.
I am using iOS 9.3.2 and Xcode 7.3.1

Both of the above answers should be tried first. If however
You're sure the capability has been activated
You're confident your app id associated with your provisioning profile has healthkit turned on and matches the app's bundle id
Then try and force the build to use that specific provisioning profile by selecting your target and going to
build settings -> code signing -> provisioning profile
and selecting it manually.
I've run into cases where get the above error in debug if 'automatic selection' is being used

That error is due to the fact that you have not added the HealthKit Entitlement to your target.
Go to your project settings in Xcode.
From there, navigate to the "Capabilities" Tab.
Scroll down until you see "HealthKit" and flip the switch to on.
Xcode will now add the HealthKit Entitlement to you Info.plist, your {ProjectName}.entitlements file, and your App ID on iTunes Connect
After following these steps, try to run your app again. This time around it should work.

Activate Health kit in Capabilities
If still not worked
check:
Does your provisioning profile includes support for HealthKit?
Does your bundle identifier use the same ID referenced in the provisioning profile with support for HealthKit?

Some additional info that might help. If, under the HealthKit Capabilities the first step "add health kit entitlement to your app id" shows an error, and you have a "Fix This" button which does not do the job... read on...
Many times after working on multiple HealthKit test projects, you may find you have a Bundle ID that matches another Bundle ID used with another HealthKit project (say you duplicated the one project to spin off another test). This contention will show up as an error under the first checkmark in "iOS dev"s picture "add health kit entitlement to your app id". The error listed in the capabilities section unfortunately calls it an "app id" when you need to change the "Bundle ID". Add a number (or some character) in your bundle id string to make it unique. Then the "Fix" button in the HealthKit capabilities settings will work.
The Bundle ID (aka "App ID") is found under the "General" tab to the left of the "Capabilities" tab.

This is bcz you have not Open the Capabilities tab in the target editor, and turn on the HealthKit switch.
and to resolve permission issues , add the following keys in info.plist and write causes.. according to your project requirements.
1.Health Update Usage Description
2.Health Records Usage Description
3.Health Share Usage Description
You can go ahead with free developer account also for authorisation purpose.
good luck

I did add both
NSHealthShareUsageDescription and NSHealthUpdateUsageDescription (make sure the values to be greater than 12 characters - read it somewhere) in Info.plist
Next, similar to Jorge Luis Jiménez screenshot
First go to the project (As I show in the image)
Open projects and target lists
Click on the Apps target (no need for watchkit extension)
Now click on the + sign (Add Library) at the top right
Add HealthKit.

I had a similar error when trying to start a workout on my AppleWatch from the iOS device, using this method:
healthStore.startWatchApp(with: configuration, completion) { } method.
Interestingly enough, I had this error only in the Release mode when the HealthKit entitlement was added only to the WatchKit Extension target. Everything was working well in Debug.
Adding HealthKit entitlement also to the iOS target fixed the issue, but you won't be aware of this requirement until you run your app in Release or through the TestFlight.
Hope, this info will help someone

Related

New Swift app Lister error: "No matching provisioning profiles found", "App ID with Identifier ... is not available"

I downloaded the sample code for the Lister app from Apple's developer website and am trying to build the Swift version to my iPhone 5S running iOS 8 Beta 5. I've changed everything to com.mycompany.Lister, but when I try to build it, it comes up with the following error.
No matching provisioning profiles found
None of the valid provisioning profiles allowed the specified entitlements: com.apple.developer.ubiquity-container-identifiers. Xcode can resolve this issue by downloading a new provisioning profile from the Member Center.
So I click "Fix Issue", it loads for a few seconds and comes back to me with this message:
An App ID with Identifier 'com.example.apple-samplecode.Lister.ListerToday' is not available. Please enter a different string.
I thought I had already changed everything to com.mycompany.Lister, but maybe I'm missing something hidden somewhere.
In your Build Settings change the Code Signing Identities from Distribution to Developer or don't code sign.
As per #markerberg's comment: The trick is to go through the compile settings for all 8 items (toggle via drop down in the upper left corner of build settings). For each of the targets you need to change all the code signing options to "don't code sign". Then it works right away.
I fixed this by creating an "App Store" distribution provisioning profile for my App on the developer.apple.com provisioning portal. The reasoning is outlined here. https://developer.apple.com/library/ios/qa/qa1830/_index.html
I am fairly sure that Xcode did this for me automatically last time I created an objective-C app, but this is my first Swift app and somehow it seems i had to do it manually even though I was just submitting for beta testing via TestFlight.
I was following instructions mentioned in the ReadMe file provided with the source code (It is called iOS and Watch Quick Start). But while using Xcode's 'Fix Issue' option for creating Provisioning Profiles, I was getting the error mentioned above.
I had to quit and restart Xcode to solve this issue. After restarting Xcode, Fix Issue option seemed to be working for me.

Error Validating and uploading App to iTunes Connect

This is driving me crazy. I've tried searching for answers and nothing quite matches my problem.
I've successfully archived my app and need to upload it to iTunes Connect. Apple recommends Application Loader but first needs to be done in Xcode. When I attempt to validate or Distribute the app in Xcode, I get an error saying "No Identities are available for signing"
I'm confused because I've wiped my certificates and profiles clean but I continue to get this message. Any ideas what I'm missing?
"No identities available for signing" can get frustrating. What you should do is regenerate your distribution certificate and profile, that should fix the issue.
If you need help regenerating: Download and open the new distribution certificate, which will store it in your keychain. Then, drag-and-drop the profile into your Xcode organizer. Next, your going to click on the project in the upper left (it has a blue icon next to it), that will bring up the projects info. There should be 2 tabs at the top of the screen, "Info" and "Build Settings". When you click on Build Settings, the option to change the code signing is about halfway down the screen. When I ran into this issue, I had to change every single one of the code signing options to iPhone Distribution. (It might not be necessary to change every field, but I did). You should be good to go after this, let me know if you have anymore issues.
I solved the problem by deleting ALL dev profiles and recreating a single provisional profile for Distribution and Developing each. Xcode then selected the profiles automatically without me having to import them into Xcode.

code signing is required for product iOS after changing Project Name

Since I've changed the project name (Packaging -> Product name) of my project for release on app store i'm getting the code signing error(CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 5.0'). I've deleted all provisioning, all certificate and reissued them. But it doesn't help a thing....
I'm trying the whole day but nothing helps. Please help!
Thnx
ps. I have the problem if i use the archive function. Testing on the iPhone doesn't give any problems
CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 5.0'
This error occurs for the simple reason that you don't have the "target" code-signing-identity fields set. If you just set the project-level values then they're not pushed down to the target. You need to explicitly set the "target". This solved my problem.
It's not that your profile and certificate are out of sync. As the error says "code signing is required". This indicates that you have not signed the app.
if there is error like CodeSign error: code signing is required for product type 'Application' in SDK 'iOS X.X') and if you are using Xcode 4.2 and 4.3 SDK than probably following could be a one kind of solution..If you have changed the provisioning profile or changed the code signing identity configuration due to changes while submitting the app or a new version or added a new code sign identity configuration. This error happens when the provision is not matching the bundle id & profile, you can do "Edit Scheme" (just after the run button double click on the project name), Do Edit Scheme.....follow image below
Select your code signing identity profile on the left, like archive and check the right hand side build configuration is matching & you have selected the Code Signing Identity based on the info.plist bundle setting & matching distribution profile, which is present.
I think your bundle identifier changed with the app name-change, so you will need to recover it.
Double-click the project file, then the target; look in the section called "Summary".
Change the first text field, named "Identifier", to the identifier of your app in the Developer Portal.
I got this error after a source control update, the "Active scheme" was changed to "iOS Device". Changing it back to iPhone X.Y Simulator fixed the problem.

Code signing error when archive with release setting, not with debug

I get the following error when I want to archive my app:
CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 4.3'
If I edit scheme and set it to Debug it works. But I cannot send the archive to apple the organizer gives the following error then:
No suitable application records were found.
Please make sure that you have set up a record for this application on iTunes Connect.
Which is strange because my bundle id is the same as the last part of the identifier in Xcode...
Does anyone know where I have to look for?
Thnx!!
You need to make sure that you have a Code Signing profile selected for your Target as well.
Same error message from XCode 4 for me, but solution was to go into iTunesConnect, click on the app in the "Manage my apps" section, click "View details" and then "Ready for Upload" (or somesuch... can't see it anymore).
This seems to shunt the app along a step in the appstore, which then makes it possible to validate and (I hope) submit the app from XCode.
Horrible process. Two apps in the store, up to my third, and still find this process confusing.
Both set the Code Signing in the (project->Bulding Settings) and (Targets->Building Settings).
It work well for me in the Xcode 4.3.1 ,Hope it's usefull for you.

The executable was signed with invalid entitlements

So here we are yet again. I already have an app on the app store, that took me 2 days to get past all the errors and just get the thing on there.
Right now, I'm trying to put the 1.1 update on my brother's iPod Touch for testing. I pressed 'Use for development'. That's fine, works. Then i build and go, and it says 'The iPod “Dans Ipod touch” doesn’t have the provisioning profile with which the application was signed.' so i press Install And Run to install the provisioning profile, and then get 'The executable was signed with invalid entitlements'.
I'll be clear - all i want to do right now is to test the app on an iPod Touch, which is plugged into the computer. How do I get past this error and do that? I have what i thought was a valid provisioning profile selected in active target and active executable, but apparently that isn't enough. Any ideas?
Couple of easy things to try:
Do a Clean before building again.
Go to Xcode's Organizer and click on all the Profiles, checking they are valid. Xcode'll throw up warning text if say, something is missing in Keychain.
Make sure your profile contains your iPod device UDID. Make sure that the certificate with which the profile is signed is installed in your keychain. Also make sure the bundle id in your profile and app info.plist match.
Outdated provisioning profiles can often be a problem. Click on your Project and your Target and then individually check the provisioning profile for each code signing identity (Ad Hoc, Debug, Release etc.) by actually clicking on it. Note that it might look like the right profile, but when you click on it, it appears at the bottom of the list in 'others'. This usually means XCode is referring to an older profile. Make sure you now select the current, up-to-date profile from the list above. It is best to check ever Code Signing Identity individually just to make sure.
Once done, I recommend cleaning the project and deleting the app from your device before running it again.
Also, check your profile in Organiser and make sure it has a Green Tick (Valid Profile) and in the Provisioning Portal to ensure the required device is included in the profile.
Go to Window -> Organizer -> Devices
and then go to the connected device's Provisioning Profiles tab.
Note the name of the currently valid profile (must have a green tick icon).
Click the project then go to Project -> Build Settings -> Code Signing
Then copy the appropriate profile name into the Code Signing Identity field.
Clean the project
Then run the program on the device
In one case, to solve this issue, I also had to add the provisioning profile on the iphone's provisioning profiles, available only on this phone, from Organizer>Devices. It is strange, because this device is the only one that require that action. (Anyway I'm Newbie)