在.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+");