在iOS上保存(私人)应用程序设置? [英] Save (Private) Application Settings on iOS?

查看:176
本文介绍了在iOS上保存(私人)应用程序设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 NSUserDefaults 用于保存/恢复 用户 偏好设置。 应用 的等效类是什么?例如,应用程序可能具有最后运行字段;或者它可能有一个字段,用于在应用程序级别使用的设备的唯一标识。

I'm aware of NSUserDefaults for saving/restoring user preferences. What is the equivalent class for an application? For example, the application may have a "last run" field; or it may have a field for a unique identification of the device for use at the application level.

我的目的是保持应用程序的设置(不是用户的设置)设置应用程序,而不是在iTunes,Time Machine,{whatever}中备份这些设置。

My intention is to keep the application's settings (not user's settings) out of the Settings Application, and not backup those settings in iTunes, Time Machine, {whatever}.

我为Java和C#收到很多噪音,但不是很多对于iOS / iPhone / iPad。

I'm getting a lot of noise for Java and C#, but not much for iOS/iPhone/iPad.

推荐答案

如果您可以通过NSUserDefaults存储值,那么也可以存储应用程序首选项。

if you can store value by NSUserDefaults, then it is good to store application preferences too.

或在项目中添加settings.plist并阅读(稍后您不会更改)

or add settings.plist on your project and read that (what you are not changing later)

和你可以使用像。,

+ (NSDictionary*)getBundlePlist:(NSString *)plistName
{
    NSString *errorDesc = nil;
    NSPropertyListFormat format;
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];
    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
    NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                          propertyListFromData:plistXML
                                          mutabilityOption:NSPropertyListMutableContainersAndLeaves           
                                          format:&format errorDescription:&errorDesc];
    return temp;
}

+ (id) getPropValue:(NSString *)PropertyName
{   // I am supposing you had add your app preferences on settings.plist.
    return [[Property getBundlePlist:@"settings"] objectForKey:PropertyName];
    //here Property is my class name, then you can use value by 
    //NSString *value = [Property getPropValue:@"setting1"];
}

这篇关于在iOS上保存(私人)应用程序设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆