gpt4 book ai didi

iphone - 如何写入AppName-Info.plist

转载 作者:行者123 更新时间:2023-12-01 17:32:26 24 4
gpt4 key购买 nike

我手动在我的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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com