If you have an enterprise iOS account, you can distribute apps internally using an enterprise distribution certificate. Here are some instructions on how to get an installable IPA via shell commands which you can automate as part of a build process.

You need to have your code signing production certificate downloaded and installed into your Keychain on your build machine. Xcode can do this, or you can download the certificate from the Apple Developer site.

Also, you need to have a mobile provisioning profile installed. The mobile provisioning’s “App ID” should be a prefix (say com.example.*) of your app’s bundle ID (such as com.example.LoremIpsum). Again, you can download via Xcode or via the developer site.

Gather (Optional) Information

While the code signing and provisioning information can be set in the Xcode project’s build configuration, you may want to override the information in your build.

Code Sign Identity

If you need to specify your code signing identity during the build, find your certificate in the Keychain and get the Common Name of the certificate.

The production certificate’s Common Name will be the CODE_SIGN_IDENTITY value.

Mobile Provisioning Profile

If you downloaded the mobile provisioning file, you can open the provisioning profile and find the UUID value in the plist.

If you have downloaded the profile in Xcode, you can go back to Xocde and open the Accounts panel in the Xcode Preferences, look at your logged in Apple ID and View Details, and then find your Provisioning Profile. Right click on the name of the Provisioning Profile and click Show in Finder. You will see a file selected in ~/Library/MobileDevice/Provisioning Profiles. The filename is usually named <UUID>.mobileprovision, or you can verify by opening up the file and find the UUID value.

The UUID will be the PROVISIONING_PROFILE value.

Build an xcarchive

Assuming that LoremIpsum is your Xcode project, you can run the following in your shell:

export BUILD_DIR=$(pwd)/build

mkdir -p $BUILD_DIR

xcrun xcodebuild -project LoremIpsum.xcodeproj -scheme LoremIpsum clean

xcrun xcodebuild CODE_SIGN_IDENTITY="$CODE_SIGN_IDENTITY" PROVISIONING_PROFILE="$PROVISIONING_PROFILE" -project LoremIpsum.xcodeproj -scheme LoremIpsum archive -archivePath LorenIpsum.xcarchive

You now have an Xcode archive which is similar to what is submitted to the App Store.

Export your app from xcarchive

The export archive option in xcodebuild allows a few options which will be saved in a plist file. The $TEAM_ID is the prefix in the App IDs in the Apple Developer portal. It can also be found in the mobile provisioning profile file as TeamIdentifier.

<?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>method</key>
        <string>enterprise</string>
        <key>embedOnDemandResourcesAssetPacksInBundle</key>
        <true/>
        <key>compileBitcode</key>
        <true/>
        <key>teamID</key>
        <string>$TEAM_ID</string>
</dict>
</plist>

The above options compile the Bitcode enabled app and add all of the resources into the app (instead of having on-demand resources).

Then just run:

xcrun xcodebuild -exportArchive -archivePath LorenIpsum.xcarchive -exportPath $BUILD_DIR/ipa -exportOptionsPlist $PATH_TO_PLIST_FILE

You should finally have your app’s IPA in the $BUILD_DIR/ipa directory which you can install by dragging and dropping the IPA to iTunes and then syncing your device with iTunes.