The following method should do what you want. As @rbrockerhoff says the mobile provisioning profile is a coded CMS message. This method uses a decoder for the first decoding of data using CMS functions, and then creates a plist string / content from the decoded data. Then this string can be converted to a dictionary, which is returned from the method. The dictionary will contain all the details from the profile of the provision of mobile services.
- (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; }
source share