IOS沙盒

时间:2024-01-03 19:38:20

可以先在程序打印沙盒路径:

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