Recently I shipped an enterprise app (distributed via HockeyApp) whose provisioning profile expired. As a result the app would not launch at all. No alert is presented to the user when a provisioning profile expires which is a very unfortunate situation.
Xcode warned me a few weeks before the provisioning profile would expire, so I renewed the profile and the warning went away. Unfortunately, I forgot to actually update the provisioning profile in Xcode’s build settings so I shipped an app that expired a few days after it was released.
I’d like to avoid this fiasco next year when the provisioning profile expires again. Is there something I can do to enforce checking that the provisioning profile doesn’t expire soon?
Here is a python script that will abort the build if the provisioning profile expires in less than 15 days. This script is meant to be run as a build phase script.
Note that this script will also work when run as part of an Xcode Bot integration.
#!/usr/bin/python
import glob, os, plistlib, subprocess, sys
from os import path
from datetime import datetime
def read_mobileprovision(mobileprovision_path):
# From http://stackoverflow.com/questions/6398364/parsing-mobileprovision-files-in-bash/10490095#10490095
return plistlib.readPlist(subprocess.Popen(['security', 'cms', '-D', '-i', mobileprovision_path], stdout=subprocess.PIPE).stdout)
if os.environ['PLATFORM_NAME'] != 'iphoneos':
sys.exit(0)
provisioning_profiles_dir = '/Library/Developer/XcodeServer/ProvisioningProfiles' if os.environ['USER'] == '_xcsbuildd' else path.expanduser('~/Library/MobileDevice/Provisioning Profiles')
provisioning_profile_uuid = os.environ['EXPANDED_PROVISIONING_PROFILE']
mobileprovision_path = path.join(provisioning_profiles_dir, provisioning_profile_uuid + ".mobileprovision")
if not path.exists(mobileprovision_path):
for mobileprovision in glob.iglob(path.join(provisioning_profiles_dir, "*.mobileprovision")):
if read_mobileprovision(mobileprovision)['UUID'] == provisioning_profile_uuid:
mobileprovision_path = mobileprovision
break
print(mobileprovision_path)
expiration_date = read_mobileprovision(mobileprovision_path)['ExpirationDate']
print("Expiration Date: {}".format(expiration_date))
remaining_days = (expiration_date - datetime.now()).days
print("Remaining Days: {}".format(remaining_days))
if remaining_days < 15:
sys.exit("error: Provisioning Profile {} is expiring in {} days.".format(mobileprovision_path, remaining_days))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With