iOS:How 想知道哪个文件在 objective c 中占用应用程序的大小?

iOS:How to know which file takes much size-in-application in objective c?

我有使用以下代码的第三方项目此代码不是全部但它在应用程序包中写入大文件(比如录音)如何找到该文件?

NSError *audioSessionError = nil;
    AVAudioSession *audioSession= [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&audioSessionError];
    [audioSession setMode:AVAudioSessionModeDefault error:&audioSessionError];
    [audioSession setPreferredSampleRate:16000.0f error:&audioSessionError];
    [audioSession setPreferredInputNumberOfChannels:1 error:&audioSessionError];
    [audioSession setActive:TRUE error:&audioSessionError];
    _sampleRate= [audioSession sampleRate];

    // make a capture session that uses the audio session
    _captureSession = [[AVCaptureSession alloc]init];
    _captureSession.sessionPreset = AVCaptureSessionPreset640x480;
    _captureSession.automaticallyConfiguresApplicationAudioSession= NO;




 _startTimeMS = [[NSDate date] timeIntervalSince1970] * 1000;

    dispatch_queue_t videoQueue = dispatch_queue_create("smmaProcessingQueueVideo", NULL);
    [_videoOutput setSampleBufferDelegate:self queue:videoQueue];

    dispatch_queue_t audioQueue = dispatch_queue_create("smmaProcessingQueueAudio", NULL);
    [_audioOutput setSampleBufferDelegate:self queue:audioQueue];

相同的视频代码,以及现在,这段代码在应用程序中写入了太大的文件(最多 2 GB)。音频+视频,

我想找到并删除 file.i 尝试过的

NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSLog(@"App Directory is: %@", appFolderPath);
NSLog(@"Directory Contents:\n%@", [fileManager directoryContentsAtPath: appFolderPath]);

怎么做?任何帮助将不胜感激。

您可以通过

清除temp directory
  NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
for (NSString *file in tmpDirectory) {


    BOOL suc = [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];

    if (suc) {

        NSLog(@"done");
    }
    NSLog(@"file : %@%@",NSTemporaryDirectory(), file);
}

你可以清除cachedirectory喜欢,

         dirPaths = NSSearchPathForDirectoriesInDomains(
                                                   NSCachesDirectory, NSUserDomainMask, YES);
    docsDir = [dirPaths objectAtIndex:0];


    NSFileManager *manager1 = [NSFileManager defaultManager];

    NSArray *filesArDirectory1 = [manager contentsOfDirectoryAtPath:docsDir error:nil];

    NSError *err1;

    for (NSString *file2 in filesArDirectory1) {

        BOOL success = [manager1 removeItemAtPath:[NSString stringWithFormat:@"%@%@", docsDir,file2] error:&err1];

        if (!success || err1) {
            NSLog(@"error description : %@",[err1 localizedDescription]);
            NSLog(@"failed2");

        }
        else{
            NSLog(@"Success2");
        }
        NSLog(@"files : %@",file2);

    }

如果这个目录存储数据,请尝试清除这两个目录。检查您的文档目录是否存储大数据,然后您还需要对其进行管理。

希望这会有所帮助:)