所以,我正在尝试打开一个 .mobileprovisioning 配置文件来读取里面的内容......这就是我正在做的:
NSString *path = [pathURL path];
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
当然,我读取了数据,但我没有找到将这些数据转化为有用的东西的方法...NSDictionary、NSString 或其他...
我已经试过了:
NSString *newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
有什么想法吗?我确定这是一个编码问题,但在阅读和谷歌搜索了一段时间后我无法解决它......我认为配置文件保存为十六进制,但我不知道如何从目标中读取它 - C。我找到了这个,但没有有用的答案。
How to convert NData populated with hex values to NSString
谢谢!
最佳答案
下面的方法应该做你想做的。正如@rbrockerhoff 所说,移动配置文件是编码的 CMS 消息。此方法使用解码器首先使用 CMS 函数解码数据,然后从解码数据创建 plist 字符串/内容。然后可以将该字符串转换为从该方法返回的字典。字典将包含来自移动配置文件的所有详细信息。
- (NSDictionary *)provisioningProfileAtPath:(NSString *)path {
CMSDecoderRef decoder = NULL;
CFDataRef dataRef = NULL;
NSString *plistString = nil;
NSDictionary *plist = nil;
@try {
CMSDecoderCreate(&decoder);
NSData *fileData = [NSData dataWithContentsOfFile:path];
CMSDecoderUpdateMessage(decoder, fileData.bytes, fileData.length);
CMSDecoderFinalizeMessage(decoder);
CMSDecoderCopyContent(decoder, &dataRef);
plistString = [[NSString alloc] initWithData:(__bridge NSData *)dataRef encoding:NSUTF8StringEncoding];
NSData *plistData = [plistString dataUsingEncoding:NSUTF8StringEncoding];
plist = [NSPropertyListSerialization propertyListWithData:plistData options:NSPropertyListImmutable format:nil error:nil]
}
@catch (NSException *exception) {
NSLog(@"Could not decode file.\n");
}
@finally {
if (decoder) CFRelease(decoder);
if (dataRef) CFRelease(dataRef);
}
return plist;
}
关于objective-c - 使用 Objective-C 读取 .mobileprovisioning 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19201040/