1

How can I switch on Keychain Sharing and Push Notifications via xcodebuild (XCode 9)? Are there any variants?

Dmitry Zimin
  • 285
  • 4
  • 12

3 Answers3

1

On xcode, click on your project, then capabilities and finally switch on Keychain sharing and Push Notifications

enter image description here

Claudio
  • 5,078
  • 1
  • 22
  • 33
0

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!

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Thank for answer Michael Dautermann! Yes, my question was about xcodebuild but not Xcode because i need use it in Teamcity. I'll try your decide. – Dmitry Zimin Nov 23 '17 at 11:07
  • Can I use two files projectName.plist and projectName.entitlements for a flag -exportOptionsPlist? For example: xcodebuild -exportArchive -exportOptionsPlist projectName.plist projectName.entitlements -archivePath test.xcarchive -exportPath – Dmitry Zimin Nov 23 '17 at 13:33
  • If you run `xcodebuild -help` you'll see the options for the `exportOptionsPlist` file. It does not appear to provide any way to specify entitlements, so I don't think the last bit will work in this answer. The only entitlement that appears to be setable is `iCloudContainerEnvironment` – Michael McGuire Apr 04 '18 at 23:47
0

It worked for me by putting the entitlement file "push.entitlements" at the root and add the CODE_SIGN_ENTITLEMENTS="push.entitlements" at the xcodebuild archive command.

xcodebuild archive -project yourproject -scheme yourscheme -configuration Release -sdk iphoneos -archivePath \"yourpath" CODE_SIGN_IDENTITY=\"{$code_sign_identity}\" PROVISIONING_PROFILE_SPECIFIER=\"{$provisioning_profile}\" CODE_SIGN_STYLE=\"Manual\" CODE_SIGN_ENTITLEMENTS=\"push.entitlements\"

I got the idea from this post: Post iOS10 / Xcode 8.0 "Missing Push Notification Entitlement" error after build for iTunes Store