Skip to content

Instantly share code, notes, and snippets.

@iHTCboy
Created January 14, 2020 10:00
Show Gist options
  • Save iHTCboy/0d9e3f751ef1ece48d3fd8992bceffdd to your computer and use it in GitHub Desktop.
Save iHTCboy/0d9e3f751ef1ece48d3fd8992bceffdd to your computer and use it in GitHub Desktop.
读取 iOS 应用中的证书信息
static NSString *bundleTeamIdentifier(void)
{
NSString *mobileProvisionPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"embedded.mobileprovision"];
FILE *fp=fopen([mobileProvisionPath UTF8String],"r");
char ch;
if(fp==NULL) {
printf("file cannot be opened/n");
return NULL;
}
NSMutableString *str = [NSMutableString string];
while((ch=fgetc(fp))!=EOF) {
[str appendFormat:@"%c",ch];
}
fclose(fp);
NSString *teamIdentifier = nil;
NSRange teamIdentifierRange = [str rangeOfString:@"<key>com.apple.developer.team-identifier</key>"];
if (teamIdentifierRange.location != NSNotFound) {
NSInteger location = teamIdentifierRange.location + teamIdentifier.length;
NSInteger length = [str length] - location;
if (length > 0 && location >= 0) {
NSString *newStr = [str substringWithRange:NSMakeRange(location, length)];;
NSArray *val = [newStr componentsSeparatedByString:@"</string>"];
NSString *v = [val firstObject];
NSRange startRange = [v rangeOfString:@"<string>"];
NSInteger newLocation = startRange.location + startRange.length;
NSInteger newLength = [v length] - newLocation;
if (newLength > 0 && location >= 0) {
teamIdentifier = [v substringWithRange:NSMakeRange(newLocation, newLength)];
}
}
}
return teamIdentifier;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment