您可以将调试日志写入文件,测试后您可以看到它们。
@interface LogFile : NSObject
+ (void)WriteLogWithString:(NSString *)log;
@end
这是实现文件
@implementation LogFile
+ (NSString*)CurrentSystemTime {
return [[NSDate date] description];
}
+(NSString*)getDocumentsPath
{
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
return path;
}
+ (NSString*)getLogFilePath
{
NSString *loggingFilePath = nil;
loggingFilePath = [[self getDocumentsPath] stringByAppendingPathComponent:@"/MYLogFile.txt"];
return loggingFilePath;
}
+ (void)WriteLogWithString:(NSString *)log
{
if(log != nil){
NSString *locationFilePath = [self getLogFilePath];
NSString *str = [NSString stringWithFormat:@"%@ %s [Line %d]: %@", [self CurrentSystemTime],__PRETTY_FUNCTION__,__LINE__,log];
FILE *fp = fopen([locationFilePath UTF8String], "a");
fprintf(fp,"%s\n", [str UTF8String]);
fclose(fp);
}
}
@end
现在你必须像这样调用方法
[LogFile WriteLogWithString:@"sachin thakur"];