iOS*_*Fun 8 notifications runtime provisioning profiles ios
我有一个应用程序,我经常通过ad-hoc分发方法传递给测试人员.其中一些测试人员"关注",并且对配置文件和季度到期有足够的了解,并且可以(如果我忘记)给我一个重建新版本供他们测试的推动.
然而,一些用户似乎总是达到停止运行的程度然后婊子和呻吟 - 尽管他们可能会忽略iOS级别的提醒.
我的问题是,我可以在运行时以编程方式获取到期日期并执行我自己的"应用程序内"警报或系统通知,以提醒他们下载新版本吗?
你正在寻找类似的东西
"<key>ExpirationDate</key><date>2014-12-06T00:26:10Z</date>" in [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]
Run Code Online (Sandbox Code Playgroud)
但到那里并不容易!此代码可以改进,部分内容基于其他stackoverflow帖子.注意:另一种选择是将项plist和/ plist之间的所有内容加载到plist(字典)中.但既然我们已经在那里,我们只需手工找到兄弟姐妹.
- (NSString*) getExpiry{
NSString *profilePath = [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"];
// Check provisioning profile existence
if (profilePath)
{
// Get hex representation
NSData *profileData = [NSData dataWithContentsOfFile:profilePath];
NSString *profileString = [NSString stringWithFormat:@"%@", profileData];
// Remove brackets at beginning and end
profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""];
profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(profileString.length - 1, 1) withString:@""];
// Remove spaces
profileString = [profileString stringByReplacingOccurrencesOfString:@" " withString:@""];
// Convert hex values to readable characters
NSMutableString *profileText = [NSMutableString new];
for (int i = 0; i < profileString.length; i += 2)
{
NSString *hexChar = [profileString substringWithRange:NSMakeRange(i, 2)];
int value = 0;
sscanf([hexChar cStringUsingEncoding:NSASCIIStringEncoding], "%x", &value);
[profileText appendFormat:@"%c", (char)value];
}
// Remove whitespaces and new lines characters
NSArray *profileWords = [profileText componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//There must be a better word to search through this as a structure! Need 'date' sibling to <key>ExpirationDate</key>, or use regex
BOOL sibling = false;
for (NSString* word in profileWords){
if ([word isEqualToString:@"<key>ExpirationDate</key>"]){
NSLog(@"Got to the key, now need the date!");
sibling = true;
}
if (sibling && ([word rangeOfString:@"<date>"].location != NSNotFound)) {
NSLog(@"Found it, you win!");
NSLog(@"Expires: %@",word);
return word;
}
}
}
return @"";
}
Run Code Online (Sandbox Code Playgroud)
斯威夫特版本:
// 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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3118 次 |
| 最近记录: |