2013-05-02 38 views
0

我已經創建了一個日誌文件唱下面的代碼。在哪個位置創建的txt文件將被存儲在ios設備中

-(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]; 

但我無法尋找到該日誌文件我的iOS設備上創建的物理,它將被保存在iOS設備?

+1

您可以找到答案到您的解決方案在這[URL] [1] [1]:http://stackoverflow.com/questions/12323194/logging-from-the-iphone-where -is-the-file?rq = 1 – Saeed 2013-05-02 03:52:27

+0

這是非常有用的.http://stackoverflow.com/a/12323485/1119440 – Ramprasad 2013-05-02 04:25:40

+0

如果我從MAC刪除設備日誌文件不更新 – Ramprasad 2013-05-02 07:03:25

回答

2

它是一個單獨的沙箱目錄內:在

/var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents 

XXXX... etc是一個UUID,當應用程序被安裝到該裝置隨機生成的。

除非您的設備已越獄,否則無法訪問此目錄。

+0

如果我從MAC中刪除設備,日誌文件不會更新 – Ramprasad 2013-05-02 10:14:57

相關問題