How can I switch on Keychain Sharing and Push Notifications via xcodebuild (XCode 9)? Are there any variants?
What you're asking for is actually somewhat tricky to do directly via xcodebuild
. The EASIEST thing to do is exactly what Claudio says up there: change the settings in your target's Capabilities section directly. +1 to him! Changes you make for capabilities within the target WILL get picked up in all of your builds by default, unless you use my methods below to explicitly change them during build time.
If you want to do this via xcodebuild
only (without opening Xcode), then read further:
If we were talking about Build Settings (i.e. compile time options), then changing settings could be as easy as something like:
xcodebuild -workspace DmitryWorkspace.xcworkspace -scheme "YourAppName" -showBuildSettings
But since you're actually trying to modify entitlements & capabilities (whether an app has the ability to do certain things), the thing you really need to do is to have different .entitlements
files that toggle these options. An .entitlement
file is basically just another name for a plist
file and it typically looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.myke.TestingSomething</string>
</array>
</dict>
</plist>
Those two keys there are for push notifications and keychain sharing.
And to pick up the entitlements file via xcodebuild
, you could do something like:
xcodebuild -exportArchive -exportOptionsPlist projectName.entitlements -archivePath test.xcarchive -exportPath .
I haven't tried this last part myself (I'd rather do Claudio's solution for my own projects), but I read up on this solution via this related blog posting. Good luck!