Skip to content

Instantly share code, notes, and snippets.

@bindle
Created November 5, 2010 02:08
Show Gist options
  • Save bindle/663541 to your computer and use it in GitHub Desktop.
Save bindle/663541 to your computer and use it in GitHub Desktop.
reads a plist file for an application
/* reads a plist file for an application */
/* gcc -o plist-dump plist-dump.m -framework Foundation */
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import <stdio.h>
int main(int argc, char * argv[]);
int main(int argc, char * argv[])
{
NSPropertyListFormat format;
NSAutoreleasePool * pool;
NSMutableArray * array;
NSDictionary * temp;
NSString * plistPath;
NSString * errorDesc;
NSData * plistXML;
NSString * value;
NSUInteger u;
errorDesc = nil;
if (argc != 2)
{
fprintf(stderr, "Usage: %s <plist>\n", argv[0]);
return(1);
};
pool = [[NSAutoreleasePool alloc] init];
plistPath = [NSString stringWithUTF8String:argv[1]];
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath])
{
NSLog(@"%@ -- file not found\n", plistPath);
[pool release];
return(1);
};
plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
temp = (NSDictionary *)[NSPropertyListSerialization
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
if (!(temp))
{
NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
[pool release];
return(1);
};
printf("Bundle display name: %s\n", [[temp objectForKey:@"CFBundleDisplayName"] UTF8String]);
printf("Bundle Version: %s\n", [[temp objectForKey:@"CFBundleVersion"] UTF8String]);
printf("Bundle identifier: %s\n", [[temp objectForKey:@"CFBundleIdentifier"] UTF8String]);
array = [NSMutableArray arrayWithArray:[temp objectForKey:@"CFBundleSupportedPlatforms"]];
for (u = 0; u < [array count]; u++)
printf("Supported OS: %s %s\n", [[array objectAtIndex:u] UTF8String], [[temp objectForKey:@"MinimumOSVersion"] UTF8String]);
array = [NSMutableArray arrayWithArray:[temp objectForKey:@"UIDeviceFamily"]];
for (u = 0; u < [array count]; u++)
printf("Supported Device: %i\n", [[array objectAtIndex:u] intValue]);
[pool release];
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment