恢复过去的NSLog

时间:2014-06-04 03:43:47

标签: ios cocoa core-data nslog

使用我的应用程序的测试人员几天前遇到了看似无法重现的错误。我相信我的应用程序记录的NSLog可能提供有关该问题的信息,但Xcode Organizer控制台仅记录260个左右的前一行。是否有一些日志文件位于设备上,提供更多的NSLog?测试人员有一个越狱设备,因此访问根目录不应该成为一个问题。

1 个答案:

答案 0 :(得分:2)

为什么不使用PList存储日志?

我开发了一些基于位置的应用。我总是需要在某个区域开车来测试位置更新区域监控等的准确性。我将这些日志存储到PList中我将分析日志在我完成一次跑步之后在PList上。

示例代码:

-(void)addLocationToPList{

  NSString *plistName = [NSString stringWithFormat:@"Location.plist"];
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *docDir = [paths objectAtIndex:0];
  NSString *fullPath = [NSString stringWithFormat:@"%@/%@", docDir, plistName];

  NSMutableDictionary *savedProfile = [[NSMutableDictionary alloc] initWithContentsOfFile:fullPath];

  if (!savedProfile){
    savedProfile = [[NSMutableDictionary alloc] init];
    self.shareModel.myCurrentLocationArray = [[NSMutableArray alloc]init];
  }
  else{
    self.shareModel.myCurrentLocationArray = [savedProfile objectForKey:@"locationArray"];
  }

  if(self.shareModel.myBestLocationDictFromTracker)
  {
      [self.shareModel.myCurrentLocationArray addObject:self.shareModel.myBestLocationDictFromTracker];
      [savedProfile setObject:self.shareModel.myCurrentLocationArray forKey:@"locationArray"];
  }

  if (![savedProfile writeToFile:fullPath atomically:FALSE] ) {
    NSLog(@"Couldn't save Location.plist" );
  }
}

每当有位置更新时,我都会调用上面的函数将位置添加到PList。您可以根据您真正需要记录的内容以任何方式使用它。

我认为它比Organizer Console日志好得多,因为您可以提取PList Out并在Mac上保留副本以供将来分析等。我正在使用iFunBox来访问/解压缩PList。 / p>