Skip to content

Instantly share code, notes, and snippets.

@bradya
Forked from mxpr/1-watchkit-update-plists.py
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradya/6ef2b5a90a0c4620fd0f to your computer and use it in GitHub Desktop.
Save bradya/6ef2b5a90a0c4620fd0f to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment