debugFile
当您想要将调试信息写入本地文件时,也许这个存储库能帮到您
介绍
-
SuspendButton
这是一个悬停按钮;悬停按钮提供了一个 itemsData 属性,用于配置您在点击悬停按钮后需要操作的子菜单。itemsData 的格式
button.itemsData = @[ @{@"on":[^(UIButton* btn){ // your code } copy]}, @{@"showFile":[^(UIButton* btn){ // your code } copy]} ];
-
YYFileManager
这个类存储/读取调试信息,提供了读写接口,默认情况下存储在 document/debug/debug_net_ios.txt 文件中(如果未设置文件存储路径)
+ (instancetype)standardDefault; // stored in debug_net_ios.txt - (instancetype)init; // stored in debug_net_ios.txt - (instancetype)initWithFilePath:(NSString*)filePath; // stored in a custom filepath
-
YYDebugFileSingleton
这个单例类持有您想要存储的调试信息,提供了一个 write_debug_file_enable 属性来确定是否写入调试文件。DebugInfo 用于存储您想要保存的信息;
@property (assign, nonatomic) BOOL write_debug_file_enable; @property (strong, nonatomic) NSDictionary *debugInfo;
-
YYDebugFileBrowseView
显示指定文件夹中的所有子文件,以表格方式显示。点击单元格后,您可以选择查看或分享调试文件
/** The folder you want to show */ @property (strong, nonatomic) NSString *fileDirectory;
如何使用(简单)
-
初始化您的调试按钮
#ifdef DEBUG - (void)initDebugView{ kWeakSelf; UIWindow *window = [UIApplication sharedApplication].delegate.window; UIView *subView = [window viewWithTag:20001]; if (subView) { return; } SuspendButton *button = [[SuspendButton alloc] initWithFrame:CGRectMake(kYYWinSize.width -110-100, 50, 30, 30)]; [button setTitle:@"debug" forState:UIControlStateNormal]; button.backgroundColor = [UIColor greenColor]; button.tag = 20001; [window addSubview:button]; NSString *btnTitle = @"off"; if ([YYDebugFileSingleton standardDefault].write_debug_file_enable) { btnTitle = @"on"; } button.itemsData = @[ @{btnTitle:[^(UIButton* btn){ btn.selected = !btn.selected; [btn setTitle:btn.selected ? @"on" : @"off" forState:UIControlStateNormal]; [YYDebugFileSingleton standardDefault].write_debug_file_enable = btn.selected; } copy]}, @{@"showFile":[^(UIButton* btn){ [weakSelf showDebugFileView:btn]; } copy]} ]; } - (void)showDebugFileView:(UIButton*)btn{ UIWindow *window = [UIApplication sharedApplication].delegate.window; if ([window viewWithTag:1001]) { [[window viewWithTag:1001] removeFromSuperview]; } YYDebugFileBrowseView *browseView = [[YYDebugFileBrowseView alloc] initWithFrame:window.bounds]; browseView.tag = 1001; [window addSubview:browseView]; NSString *debugDirPath = [PATH_OF_DOCUMENT stringByAppendingPathComponent:@"debug"]; browseView.fileDirectory = debugDirPath; } #endif
-
您需要存储调试信息的地方,添加方法
#ifdef DEBUG if ([YYDebugFileSingleton standardDefault].write_debug_file_enable) { [[YYFileManager standardDefault] writeDebugString:@"your debug string"]; } #endif