Ios 文本文件仅更新设备仅与xcode连接

Ios 文本文件仅更新设备仅与xcode连接,ios,Ios,我在ios中创建了一个文本文件,它存储在以下位置的数据文件中。Sandbox=>Documents=>mylogfile.txt。 仅当我使用Mac和Xcode连接设备时,此文件才会更新。如果我弹出设备,然后再次连接以查看更新的文本文件。它没有更新。它将与旧文件相同。从电脑断开连接时,日志文件不会更新。 如何随时更新文本文件 我的代码: -(void)logme:(NSString *)mymessage { NSString *content = mymessage; //G

我在ios中创建了一个文本文件,它存储在以下位置的数据文件中。
Sandbox=>Documents=>mylogfile.txt。

仅当我使用Mac和Xcode连接设备时,此文件才会更新。如果我弹出设备,然后再次连接以查看更新的文本文件。它没有更新。它将与旧文件相同。从电脑断开连接时,日志文件不会更新。 如何随时更新文本文件

我的代码:

-(void)logme:(NSString *)mymessage
{
    NSString *content = mymessage;

    //Get the file path
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *fileName = [documentsDirectory stringByAppendingPathComponent:@"locationlog.txt"];

    //create file if it doesn't exist
    if(![[NSFileManager defaultManager] fileExistsAtPath:fileName])
        [[NSFileManager defaultManager] createFileAtPath:fileName contents:nil attributes:nil];

    //append text to file (you'll probably want to add a newline every write)
    NSFileHandle *file = [NSFileHandle fileHandleForUpdatingAtPath:fileName];
    [file seekToEndOfFile];
    [file writeData:[content dataUsingEncoding:NSUTF8StringEncoding]];
    [file closeFile];
}
把这个日志文件叫做

[self logme:myHTML];

请发布创建/更新文本文件的代码,以便我们可以找到问题和解决方案:)。此日志文件每1分钟更新一次。您是否尝试添加
[file synchronizeFile]
[file closeFile]之前?不,我的应用程序在后台运行,并定期从服务器获取数据,这也不正常。即使我没有连接到PC,我也希望看到获取的数据。然后只有我可以检查它消耗了多少电池。如果它与PC连接,它总是在充电。因此,我无法测试此任务的电池消耗