Is it possible to use CloudKit from "Command Line Tool" application?

In Xcode I have created UI-less application. I tried to add following code:

import CloudKit

let container = CKContainer.default()

And it is failing with:

In order to use CloudKit, your process must have a com.apple.developer.icloud-services entitlement. The value of this entitlement must be an array that includes the string "CloudKit" or "CloudKit-Anonymous".

If I go to project and select my Command Line Tool target I don't see CloudKit capability that I usually see in UI based applications.

So, is it impossible to use CloudKit from Command Line tools?

Answered by DTS Engineer in 797800022

CloudKit access is gated by restricted entitlements, that is, entitlements that must authorised by a provisioning profile. For more on that topic, see TN3125 Inside Code Signing: Provisioning Profiles. That makes things tricky when building a command-line tool because there’s no place to put the provisioning profile (r. 125850707). The standard workaround is to put the tool in an app-like wrapper, as I explain in Signing a daemon with a restricted entitlement.

I’ve never tried this with CloudKit but I vaguely recall sending other folks down this path and not hearing any complaints. Please try it out and post back if you get stuck.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

CloudKit access is gated by restricted entitlements, that is, entitlements that must authorised by a provisioning profile. For more on that topic, see TN3125 Inside Code Signing: Provisioning Profiles. That makes things tricky when building a command-line tool because there’s no place to put the provisioning profile (r. 125850707). The standard workaround is to put the tool in an app-like wrapper, as I explain in Signing a daemon with a restricted entitlement.

I’ve never tried this with CloudKit but I vaguely recall sending other folks down this path and not hearing any complaints. Please try it out and post back if you get stuck.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Is it possible to use CloudKit from "Command Line Tool" application?
 
 
Q