iphone - iOS。应用程序更新后保护设置不被重置?

标签 iphone ios settings plist

我使用“plist”文件来存储我的设置。我找到的唯一答案是保存此目录中的文件:

NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

但我不知道该怎么做。

最佳答案

阅读文档:NSUserDefaults

The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an application to customize its behavior to match a user’s preferences. For example, you can allow users to determine what units of measurement your application displays or how often documents are automatically saved. Applications record such preferences by assigning values to a set of parameters in a user’s defaults database. The parameters are referred to as defaults since they’re commonly used to determine an application’s default state at startup or the way it acts by default.

因此您可以在 NSUserDefaults 中保存和读取您的设置。

//write to standard defaults
[[NSUserDefaults standardUserDefaults] setObject:yourObject forKey:@"kYourKey"];
[[NSUserDefaults standardUserDefaults] synchronize];

//read from standard defaults
yourObject = [[NSUserDefaults standardUserDefaults] objectForKey:@"kYourKey"];

下次尝试更具体地说明您想做什么。

关于iphone - iOS。应用程序更新后保护设置不被重置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8179292/

相关文章:

iphone - 更改应用程序名称

javascript - 抓取类中的图层内容

ios - YTPlayer将重定向到OAuth2 URL并显示“请稍候”

ios - 防止 Share Extension 中的 UINavigationBar 继承主应用程序外观设置

ruby-on-rails - 如何为 rails-settings 插件创建表单

ios - 检测空 UITextField 中的退格键

iphone - 自定义 tableView 标题导致单元格边框显示

ios - 使用 TestFlight 的 iOS 应用程序大小意外增加

android - SecurityException : Given caller package com. android.settings 未在进程 ProcessRecord 中运行

java - 哪个 Tomcat 5 上下文文件优先?