IOS沙盒
Posted workky
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IOS沙盒相关的知识,希望对你有一定的参考价值。
可以先在程序打印沙盒路径:
NSLog(@"路径%@",NSHomeDirectory());
----------------------------------------------------其中一个沙盒存储更新与读取方法方法------------------------------------------------------
#import <Foundation/Foundation.h>
@interface ConfigData : NSObject
//保存到沙盒中
+ (void)saveCache:(NSString *)keyName andString:(NSString *)str;
//从沙盒中读取
+ (NSString *)getCache:(NSString *)keyName;
@end
#import "ConfigData.h"
@implementation ConfigData
+ (void)saveCache:(NSString *)keyName andString:(NSString *)str
{
NSUserDefaults * setting = [NSUserDefaultsstandardUserDefaults];
NSString * key = [NSStringstringWithFormat:@"OrderId-%@",keyName];
[setting setObject:str forKey:key];
[setting synchronize];
}
+ (NSString *)getCache:(NSString *)keyName
{
NSUserDefaults * settings = [NSUserDefaultsstandardUserDefaults];
NSString *key = [NSStringstringWithFormat:@"OrderId-%@",keyName];
NSString *value = [settings objectForKey:key];
return value;
}
@end
以上是关于IOS沙盒的主要内容,如果未能解决你的问题,请参考以下文章