How to append string in local resource txt file for iOS sdk

后端 未结 3 1401
温柔的废话
温柔的废话 2020-12-14 22:48

I have been trying to append strings to a local resource file but I am having trouble finding a solution. I am trying to create a log file for all the function call in my ap

3条回答
  •  独厮守ぢ
    2020-12-14 23:31

    I have use following code for the above problem.

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    NSString *logPath = [[NSString alloc] initWithFormat:@"%@",[documentsDir stringByAppendingPathComponent:@"log.rtf"]];
    NSFileHandle *fileHandler = [NSFileHandle fileHandleForUpdatingAtPath:logPath];
    [fileHandler seekToEndOfFile];
    [fileHandler writeData:[text dataUsingEncoding:NSUTF8StringEncoding]];
    [fileHandler closeFile];
    

提交回复
热议问题