embedded.mobileprovison是由二进制的加密数据和普通文本字符串组成,我们使用NSPropertyListSerialization类解析普通文本字符串
首先将普通文本字符串提前出来,这里用到了NSScanner
NSString *embeddedPath = [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"];
NSString *embeddedProvisioning = [NSString stringWithContentsOfFile:embeddedPath encoding:NSISOLatin1StringEncoding error:nil];
NSScanner *scanner = [[NSScanner alloc] initWithString:embeddedProvisioning];
if (![scanner scanUpToString:@"<plist" intoString:nil]) {
NSLog(@"parse embedded.mobilerovision error, no plist markup");
return nil;
}
NSString *extractedPlist = nil; //接收普通文本字符串
if (![scanner scanUpToString:@"</plist>" intoString:&extractedPlist]) {
NSLog(@"parse embedded.mobilerovision error, no plist markup");
return nil;
}
extractedPlist = [extractedPlist stringByAppendingString:@"</plist>"]; //添加xml标签结束标记
然后就可以使用NSPropertyListSerialization解析了
NSError *error;
NSDictionary *plist = [NSPropertyListSerialization propertyListWithData:[extractedPlist dataUsingEncoding:NSISOLatin1StringEncoding] options:NSPropertyListImmutable format:nil error:&error];
if (error || ![plist isKindOfClass:[NSDictionary class]])
{
NSLog(@"parse embedded.mobilerovision error, %@",error);
return nil;
}
return plist; //返回结果
参考
https://www.process-one.net/blog/reading-ios-provisioning-profile-in-swift/
发表回复
要发表评论,您必须先登录。