I recently wrestled with the clusterfuck that is iOS code signing, so here's my setup to set up a swift xcodegen project signed with a personal (free) provisioning team. this doesn't require an apple developer account, just a regular apple id.
you'll be able to build whole thing from the command line without ever have to touch xcode ever again.
this was tested with xcode 10.0 (10A255) on High Sierra
- open xcode
- file -> preferences
- accounts
- log into your apple id
- create a personal team
- click manage certificates
- click the '+' and select "iOS Development"
save this script as xcodeteam.sh
#!/bin/sh
# pick a code signing identity and get the associated xcode team id
# requires percol (pip install percol)
cert="$( \
security find-identity -p codesigning -v \
| awk '{$1=$2=""; print $0}' \
| sed '$d' \
| sed 's/ //g' \
| sed 's/"//g' \
| percol \
)"
if [ -z "$cert" ]; then
echo "canceled"
exit 0
fi
security find-certificate -c "$cert" -p | openssl x509 -text \
| grep -o OU=[^,]* \
| grep -v Apple \
| sed s/OU=//g
install dependencies and run it
brew install python
pip3 install --user percol
export PATH="~/Library/Python/3.7/bin:$PATH"
chmod +x ./xcodeteam.sh
./xcodeteam.sh
the script will prompt you to pick one of your identities, you should pick one of the "iPhone Developer" ones that matches your apple id.
press enter to confirm and it will print out your team id. copy this, we'll need it in a moment
here's an example project that uses SnapKit
project.yml
name: example
options:
bundleIdPrefix: $(OSX_NAMESPACE).example
settings:
DEVELOPMENT_TEAM: $(OSX_DEVELOPMENT_TEAM)
targets:
Example:
type: application
platform: iOS
deploymentTarget: "8.0"
sources:
- AppDelegate.swift
- ExampleViewController.swift
- Info.plist
build.sh
#!/bin/sh
workdir="$(dirname $(realpath "$0"))"
rm -rf "$workdir/build" || exit $?
xcodegen && pod install || exit $?
xcodebuild \
-scheme Example \
-workspace example.xcworkspace \
-configuration Debug \
-allowProvisioningUpdates \
BUILD_DIR="$workdir/build" \
|| exit $?
ios-deploy --noninteractive --debug --bundle \
"$workdir"/build/Debug-iphoneos/*.app
Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target 'Example' do
pod 'SnapKit', '~> 4.0.0'
end
Info.plist (copied from https://github.com/yonaskolb/XcodeGen/blob/master/Tests/Fixtures/TestProject/App_iOS_UITests/Info.plist)
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
AppDelegate.swift
import UIKit
@UIApplicationMain
class AppDelegate : UIResponder, UIApplicationDelegate {
var window : UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
window = UIWindow(frame : UIScreen.main.bounds)
window!.rootViewController = ExampleViewController()
window!.makeKeyAndVisible()
return true
}
}
ExampleViewController.swift
import SnapKit
class ExampleViewController : UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
}
}
just put everything in one folder
install any dependency you might not have:
gem install --user cocoapods
export PATH="~/.gem/ruby/2.3.0/bin:$PATH"
brew install xcodegen ios-deploy
now you can build like so
export OSX_NAMESPACE=com.something
export OSX_DEVELOPMENT_TEAM=yourdevteam
chmod +x ./build.sh
./build.sh
yourdevteam is the team id you obtained earlier
you most likely want to export those environment variables in your
~/.bash_profile
so they persist.
if your ipad or iphone is connected to your mac, the application should pop right up and display a red screen
have fun!
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>