Reputation: 991
I'm trying to enable image document types to an app using objc. I have root access to the plist
I need to write to. Just wrapping my head around how many keys, dictionaries, & arrays needed to code this has been frustrating me for over an hour. I can't get it right.
If I'm correct I'll need to create a NSMutableArray
in a NSDictionary
in another NSMutableArray
?
I'm using NSMutableDictionary to write to the plist as below:
NSMutableDictionary *data;
if ([fileManager fileExistsAtPath: path]) {
data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
} else {
//no plist
}
This is what I need to add to the plist:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Images</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.image</string>
</array>
</dict>
</array>
Could someone point me in the right direction?
Upvotes: 0
Views: 144
Reputation: 2533
PList is the file representation of NSMutableDictionary :
You can use the following :
NSMutableDictionary *data;
if ([fileManager fileExistsAtPath: path]) {
data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
} else {
NSMutableArray *array = [[NSMutableArray alloc] init];
NSDictionary *dict = [[NSMutableDictionary alloc] init];
NSString *images = @"Images";
[dict setValue:images forKey:@"CFBundleTypeName"];
NSString *Alternate = @"Alternate";
[dict setValue:images forKey:@"LSHandlerRank"];
NSMutableArray *LSItemContentTypes = [[NSMutableArray alloc] init];
NSString *publicImage = @"public.image";
[LSItemContentTypes addObject:publicImage];
[dict setValue:LSItemContentTypes forKey:@"LSItemContentTypes"];
[data setObject:array forKey:@"CFBundleDocumentTypes"];
}
Upvotes: 1