Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
watchkit command line builds
import plistlib
# Read Plists
myAppInfoPlist = plistlib.readPlist(“MyApp/Info.plist”)
watchKitExtensionInfoPlist = plistlib.readPlist(“WatchKitExtension/Info.plist”)
watchKitAppInfoPlist = plistlib.readPlist(“WatchKitApp/Info.plist”)
# Update Watch Kit Extension Plist
watchKitExtensionInfoPlist[“NSExtension”][“NSExtensionAttributes”][“WKAppBundleIdentifier”] = watchKitAppInfoPlist[“CFBundleIdentifier”]
watchKitExtensionInfoPlist[“CFBundleVersion”] = myAppInfoPlist[“CFBundleVersion”]
WatchKitExtensionInfoPlist[“CFBundleShortVersionString”] = myAppInfoPlist[“CFBundleShortVersionString”]
# Update Watch Kit App Plist
watchKitAppInfoPlist[“WKCompanionAppBundleIdentifier”] = myAppInfoPlist[“CFBundleIdentifier”]
watchKitAppInfoPlist[“CFBundleVersion”] = myAppInfoPlist[“CFBundleVersion”]
watchKitAppInfoPlist[“CFBundleShortVersionString”] = myAppInfoPlist[“CFBundleShortVersionString”]
# Save the Plists
plistlib.writePlist(myAppInfoPlist, “MyApp/Info.plist”)
plistlib.writePlist(watchKitExtensionInfoPlist, “WatchKitExtension/Info.plist”)
plistlib.writePlist(watchKitAppInfoPlist, “WatchKitApp/Info.plist”)
xcrun xcodebuild -sdk iphoneos -config "Release"
cp watchkitapp.mobileprovision MyApp.app/WatchKitExtension.appex/WatchKitApp.app/embedded.mobileprovision
cp watchkitextension.mobileprovision MyApp.app/WatchKitExtension.appex/embedded.mobileprovision
cp myapp.mobileprovision MyApp.app/embedded.mobileprovision
xcrun codesign -d --entitlements :- MyApp.app/WatchKitExtension.appex/WatchKitApp.app 2>/dev/null > watchkitapp.xcent
xcrun codesign -d --entitlements :- MyApp.app/WatchKitExtension.appex 2>/dev/null > watchkitextension.xcent
xcrun codesign -d --entitlements :- MyApp.app 2>/dev/null > myapp.xcent
# Order is important!!
# WatchKit App
rm -rf MyApp.app/Plugins/MyWatchKitExtension.appex/MyWatchKitApp.app/_CodeSignature
xcrun codesign -f -s "Certificate Name" -- entitlements watchkitapp.xcent MyApp.app/Plugins/MyWatchKitExtension.appex/MyWatchKitApp.app
# WatchKit Extension
rm -rf MyApp.app/Plugins/MyWatchKitExtension.appex/_CodeSignature
xcrun codesign -f -s "Certificate Name" -- entitlements watchkitextension.xcent MyApp.app/Plugins/MyWatchKitExtension.appex
# Main App
rm -rf MyApp.app/_CodeSignature
xcrun codesign -f -s "Certificate Name" -- entitlements myapp.xcent MyApp.app
xcrun -sdk iphoneos PackageApplication MyApp.app -o MyApp.ipa
# Extract the contents of the ipa
unzip MyApp.ipa
# Include WatchKitSupport
mkdir WatchKitSupport
cp "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/Library/Application\ Support/WatchKit/WK" WatchKitSupport/WK
# Repackage
zip -qr MyAppWithWatchKit.ipa Payload WatchKitSupport
# https://github.com/mxpr/ios-build-utils
from utils.packager import Packager
def package():
ipa = Packager("MyAppWithWatchKit.ipa")
ipa.add("MyApp.app","Payload/MyApp.app")
ipa.add("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/Library/Application\ Support/WatchKit/WK", "WatchKitSupport/WK")
ipa.package()
@AliAyasrah

This comment has been minimized.

Copy link

commented May 20, 2015

hello
thanks for the that .

i tried to do that but i cant find "WatchKitExtension.appex" inside "MyApp.app" folder

please i need help about that
thanks

@ghost

This comment has been minimized.

Copy link
Owner Author

commented Jun 27, 2015

its under the Plugins folder
e.g. MyApp.app/Plugins/MyWatchKitExtension.appex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.