问题描述
- 怎么写AppName-Info.plist
-
添加了一个key,名为App,到AppName-Info.plist 中。通过下面代码可以获取它的值:NSBundle *mainBundle; mainBundle = [NSBundle mainBundle]; NSString *value = [mainBundle objectForInfoDictionaryKey:@"App"]; NSLog(@"App: %@",value);
但是我用了很多方法都不能改变这个值,有实现方法么?请大家帮忙啊,谢谢。
解决方案
考虑使用NSUserDefaults`
如果你想修改bundled .plist试试这个:
NSString* plistFilePath = nil;
NSFileManager* manager = [NSFileManager defaultManager];
if ((plistFilePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"mySpecial/PathTo.plist"]))
{
if ([manager isWritableFileAtPath:plistFilePath])
{
NSMutableDictionary* infoDictioio = [NSMutableDictionary dictionaryWithContentsOfFile:plistFilePath];
[infoDictio setObject:@"foo object" forKey:@"fookey"];
[infoDictio writeToFile:plistFilePath atomically:NO];
[manager setAttributes:[NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate] ofItemAtPath:[[NSBundle mainBundle] bundlePath] error:nil];
}
}
时间: 2024-10-26 18:02:00