简体   繁体   English

检查配置文件到期日期

[英]Checking for provisioning profile expiration

Recently I shipped an enterprise app (distributed via HockeyApp) whose provisioning profile expired. 最近我发布了一个企业应用程序(通过HockeyApp分发),其配置文件已过期。 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. Xcode在供应配置文件到期前几周警告我,所以我更新了配置文件并且警告消失了。 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. 不幸的是,我忘了实际更新Xcode的构建设置中的配置文件,因此我发布了一个应用程序,该应用程序在发布后几天就已过期。

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. 这是一个python脚本,如果供应配置文件在不到15天的时间内到期,它将中止构建。 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. 请注意,当作为Xcode Bot集成的一部分运行时,此脚本也将起作用。

#!/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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM