我有一个应用程序,我经常通过即席分发方法将其传递给测试人员。这些测试人员中的一些人“随时待命”,并且对调配配置文件和季度到期足够了解,并且可以(如果我忘了)给我一些帮助,以重建一个新版本供他们测试。
但是,尽管他们可能会忽略iOS级别的提醒,但一些用户似乎总是会停止运行,然后对此and之以鼻。
我的问题是,我可以通过编程方式掌握运行时的到期日期,并且可以自己发出“应用内”警报或系统通知来提醒他们拉下较新版本吗?
最佳答案
迅捷版:
// 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
}