现在的位置: 首页 > 综合 > 正文

删除NSUserDefaults所有记录

2017年02月27日 ⁄ 综合 ⁄ 共 339字 ⁄ 字号 评论关闭
//方法一
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];

//方法二
- (void)resetDefaults {
    NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
    NSDictionary * dict = [defs dictionaryRepresentation];
    for (id key in dict) {
        [defs removeObjectForKey:key];
    }
    [defs synchronize];
}

抱歉!评论已关闭.