在运行时获取配置文件的到期日期? [英] Get the EXPIRATION date of a Provisioning Profile at Run-time?

查看:25
本文介绍了在运行时获取配置文件的到期日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我经常通过临时分发方法分发给测试人员.其中一些测试人员随时待命",对配置文件和季度到期情况有足够的了解,并且可以(如果我忘记的话)鼓励我重建一个新版本以供他们测试.

I have an app that I routinely pass out to testers via the ad-hoc distribution method. Some of these testers are 'on the ball' and know enough about provisioning profiles and the quarterly expirations and can (if I forget) give me a nudge to rebuild a new version for them to test.

然而,有些用户似乎总是到了它停止运行的地步,然后抱怨它——尽管他们可能会忽略 iOS 级别的提醒.

However some of the users always seem to get to the point where it stops running and then bitch and moan about it - despite them probably dismissing the iOS level reminder.

我的问题是我可以在运行时以编程方式获取到期日期并执行我自己的应用内"警报或系统通知以提醒他们拉下较新的版本?

My question is can I programatically get hold of the expiry date at runtime and do my own 'in-app' alerts or system notifications to remind them to pull down the newer version?

推荐答案

Swift 版本:

// Returns `nil` if it fails
private func getProvisioningProfileExpirationDateAsString() -> String? {
    guard
        let profilePath = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision"),
        let profileData = try? Data(contentsOf: URL(fileURLWithPath: profilePath)),
        // Note: We use `NSString` instead of `String`, because it makes it easier working with regex, ranges, substring etc.
        let profileNSString = NSString(data: profileData, encoding: String.Encoding.ascii.rawValue)
        else {
        print("WARNING: Could not find or read `embedded.mobileprovision`. If running on Simulator, there are no provisioning profiles.")
        return nil
    }


    // NOTE: We have the `[\W]*?` check to make sure that variations in number of tabs or new lines in the future does not influence the result.
    guard let regex = try? NSRegularExpression(pattern: "<key>ExpirationDate</key>[\W]*?<date>(.*?)</date>", options: []) else {
        print("Warning: Could not create regex.")
        return nil
    }

    let regExMatches = regex.matches(in: profileNSString as String, options: [], range: NSRange(location: 0, length: profileNSString.length))

    // NOTE: range `0` corresponds to the full regex match, so to get the first capture group, we use range `1`
    guard let rangeOfCapturedGroupForDate = regExMatches.first?.range(at: 1) else {
        print("Warning: Could not find regex match or capture group.")
        return nil
    }

    let dateAsString = profileNSString.substring(with: rangeOfCapturedGroupForDate)
    return dateAsString
}

这篇关于在运行时获取配置文件的到期日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆