給ios程序添加調試日志文件 – iPhone手機開發技術文章 iPhone軟體開發教學課程

 在.plist裡添加   Application supports iTunes file sharing  YES,這樣就可以在itunes

查看日志瞭,非常方便!

NSFileManager * filemangage =[NSFileManager defaultManager];

    NSArray *paths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDir = [paths objectAtIndex:0];

    

    [filemangage changeCurrentDirectoryPath:[documentsDir stringByExpandingTildeInPath]];

    [filemangage createFileAtPath:@"log.txt" contents:nil attributes:nil];

    

    NSString * fullfilename=[documentsDir stringByAppendingPathComponent:@"log.txt"];

    const  char* pcpath = [fullfilename cStringUsingEncoding:NSASCIIStringEncoding];

    

    filelog=fopen(pcpath, "w+");

You May Also Like