我手动在我的AppName-Info.plist中添加了一个名为“App”的键,可以通过调用此代码从中获取值

NSBundle *mainBundle;
mainBundle = [NSBundle mainBundle];

NSString *value = [mainBundle objectForInfoDictionaryKey:@"App"];

NSLog(@"App: %@",value);

但是我无法用任何代码更改值。是否可能?如果是的话,该怎么办?

预先感谢您的帮助:)

最佳答案

您应该考虑使用NSUserDefaults ,或者如果您想修改捆绑的.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];
    }
}

关于iphone - 如何写入AppName-Info.plist,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15924921/

10-11 14:43