2016 0220 清除缓存

//start

-(void)clearCashSelf{

    MCLog(@"NSHomeDirectory 沙盒路径----%@",NSHomeDirectory());

    

//    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"清除缓存" message: [NSString stringWithFormat:@"清除%.2fM",fileSizeM] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"清除本地缓存" message: [NSString stringWithFormat:@"清除%.2fKB",fileSizeM] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

    alert.tag = 8899;

    [alert show];

    

}

-(float)fileSizeAtPath:(NSString *)path{

    NSFileManager *fileManager=[NSFileManager defaultManager];

    if([fileManager fileExistsAtPath:path]){

        long long size=[fileManager attributesOfItemAtPath:path error:nil].fileSize;

//        return size/1024.0/1024.0;

        return size/1024.0;

    }

    return 0;

}

-(float)folderSizeAtPath:(NSString *)path{

    NSFileManager *fileManager=[NSFileManager defaultManager];

    float folderSize;

    if ([fileManager fileExistsAtPath:path]) {

        NSArray *childerFiles=[fileManager subpathsAtPath:path];

        for (NSString *fileName in childerFiles) {

            NSString *absolutePath=[path stringByAppendingPathComponent:fileName];

            folderSize +=[self fileSizeAtPath:absolutePath];

        }

       

        return folderSize;

    }

    return 0;

}

-(void)clearCache:(NSString *)path{

    

    NSFileManager *fileManager=[NSFileManager defaultManager];

    if ([fileManager fileExistsAtPath:path]) {

        NSArray *childerFiles=[fileManager subpathsAtPath:path];

        for (NSString *fileName in childerFiles) {

            //如有需要,加入条件,过滤掉不想删除的文件

            NSString *absolutePath=[path stringByAppendingPathComponent:fileName];

            [fileManager removeItemAtPath:absolutePath error:nil];

        }

    }

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    if (alertView.tag == 8899) {

        

        if (buttonIndex == 0) {

            

            

        }else{

            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

            NSString *cachPath = [paths objectAtIndex:0];

            NSLog(@"路径 缓存 =====%@",paths);

            [self clearCache:cachPath];

            fileSizeM=0;

//            [TvDataArray removeAllObjects];

            [_TVSatand reloadData];

        }

    }else{

    if (buttonIndex==1) {

        

        MBProgressHUD *hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];

        hub.removeFromSuperViewOnHide = YES;

        hub.labelText = @"正在注销...";

        

        [[ECDevice sharedInstance] logout:^(ECError *error) {

            [MBProgressHUD hideHUDForView:self.view animated:YES];

            

            [DemoGlobalClass sharedInstance].userName = nil;

            

            [DemoGlobalClass sharedInstance].isLogin = NO;

        

//            //为了页面的跳转,使用了该错误码,用户在使用过程中,可以自定义消息,或错误码值

////            [[NSNotificationCenter defaultCenter] postNotificationName:@"zhuxiaoDengluPENINET" object:[ECError errorWithCode:10]];

//                            [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onConnected object:[ECError errorWithCode:10]];

        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];

        [user setObject:@"1122" forKey:@"registersucceed"];

        [user setObject:@"123" forKey:@"perfectInfo"];

        [user synchronize];

            Dlpontlerexple *dd=[Dlpontlerexple shareIndence];

           

            NSString  *ddd=[NSString stringWithFormat:@"%@", dd.mobileStr];

            LoginViewController *login = [[LoginViewController alloc]init];

            login.phoneStr=ddd;

            

        login.strZhuxiao = @"fanhuiLogin";

            [self.navigationController pushViewController:login animated:YES];

        [[NSNotificationCenter defaultCenter] postNotificationName:@"TUICHUzhuxiaoDenglu" object:nil];

        }];

//                    [[NSNotificationCenter defaultCenter] postNotificationName:@"zhuxiaoDengluPENINET" object:[ECError errorWithCode:10]];

        

    }

    }

}

        [[SDImageCache sharedImageCache] cleanDisk];

}

原文地址:https://www.cnblogs.com/gzz2016/p/5203652.html