Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Remove Data from doucument Directory ios

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 296
    Comment on it

    Hello friends,

    I was using to document directory to save images and video and after saving a lot my app use to crash due to memory warnings.

    So there is a way to delete content of document directory.

    -(void)deleteDD
    {
    {
    
        NSLog(@"IS it working");
        NSFileManager *fileMgr = [[NSFileManager alloc] init];
        NSError *error = nil;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSArray *files = [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:nil];
    
        while (files.count > 0) {
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSArray *directoryContents = [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error];
            if (error == nil) {
                for (NSString *path in directoryContents) {
                    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:path];
                    BOOL removeSuccess = [fileMgr removeItemAtPath:fullPath error:&error];
                    files = [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:nil];
                    if (!removeSuccess) {
                        // Error
                    }
                }
            } else {
                // Error
            }
        }
    }
    
    
    }
    

    Hope this is helpful.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: