Skip to content

Instantly share code, notes, and snippets.

@PavelGnatyuk
Created October 2, 2013 07:49
Show Gist options
  • Save PavelGnatyuk/6790321 to your computer and use it in GitHub Desktop.
Save PavelGnatyuk/6790321 to your computer and use it in GitHub Desktop.
Retrieve embedded mobile provisioning profile from the app bundle programmatically.
+ (NSString *)mobileprovision
{
#if TARGET_IPHONE_SIMULATOR
return nil;
#endif
NSString *result = nil;
NSString *profilePath = [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"];
if ( profilePath ) {
NSData *profileData = [NSData dataWithContentsOfFile:profilePath];
NSString *profileString = [NSString stringWithFormat:@"%@", profileData];
profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""];
profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(profileString.length - 1, 1) withString:@""];
profileString = [profileString stringByReplacingOccurrencesOfString:@" " withString:@""];
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];
}
NSRange range1 = [profileText rangeOfString:@"<?xml"];
if ( range1.location != NSNotFound ) {
NSRange range2 = [profileText rangeOfString:@"</plist>"];
if ( range2.location != NSNotFound ) {
NSRange range = NSMakeRange(range1.location, range2.location + range2.length - range1.location);
result = [profileText substringWithRange:range];
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment