美文网首页
iOS 清除缓存(笔记)

iOS 清除缓存(笔记)

作者: 赵永洪 | 来源:发表于2015-12-31 20:49 被阅读389次

    float tmpSize = [[SDImageCache sharedImageCache] getSize];

    NSString *clearMessage = tmpSize >= 1024 * 1024 ? [NSString stringWithFormat:@"清理缓存(%.2fM)" , tmpSize / 1024 / 1024] : [NSString stringWithFormat:@"清理缓存(%.2fK)", tmpSize / 1024];


    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:clearMessage preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

    }];


    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

    [[SDImageCache sharedImageCache]clearDisk];

    //清除内存缓存

    [[[SDWebImageManager sharedManager] imageCache] clearMemory];

    //清除系统缓存

    [[NSURLCache sharedURLCache] removeAllCachedResponses];

    }];


    [alert addAction:action2];

    [alert addAction:action1];

    [self presentViewController:alert animated:YES completion:nil];

    相关文章

      网友评论

          本文标题:iOS 清除缓存(笔记)

          本文链接:https://www.haomeiwen.com/subject/irxwhttx.html