如何写入AppName-Info.plist
我手动添加了一个名为“App”的密钥到我的AppName-Info.plist,我可以通过调用这个代码来获取它的值
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]; } }
您不应该在运行时修改您的应用程序Info.plist文件(或应用程序包中的任何内容)。 这是不好的做法,也将打破你的捆绑代码签名(这将导致无法启动应用了!)。
如果你想存储设置,你应该看看NSUserDefaults 。
这是不可能的。
默认情况下,AppName-Info.plist不会复制到构build的“复制包资源”阶段中的包中。
所以,如果你想有一个plist,你可以写入一个选项将创build它在运行时在临时文件位置,并读/写在那里。
这是研究如何做的好地方。