您是否曾经需要添加对用户操作的日志记录以便查看如何重现那种崩溃?这个 Pod 就能完成这个任务。
UILogHelper.printToConsole = false
NotificationCenter.default.addObserver(forName: UILogItem.uiLogNotification, object: nil, queue: nil) { n in
// handle log event, e.g. add it to your crash reporter's
guard let log = n.object as? UILogItem else { return }
if log.type == .viewControllerDidAppear { }
if log.type == .controlAction { }
}
此时n.object
是UILogItem
的实例,具有以下属性
@property (nonatomic) UILogItemType type;
@property (nonatomic, strong, nonnull) NSDate *timestamp;
@property (nonatomic, strong, nonnull) NSObject *object;
@property (nonatomic, strong, nullable) NSString *title;
@property (nonatomic, strong, nullable) NSIndexPath *indexPath;
这是一个相当简化的实现,如果您想添加功能请随时提出问题。一个 pull-request 会更好。
底层是用obj-c
编写的代码,它通过 swizzling 对UIApplication
、UIViewController
、UITableView
和 UICollectionView
进行操作。
如果对如何实现 swizzling 有更好的建议,请告诉我。
要运行示例项目,请克隆仓库,并首先从 Example 目录中运行 pod install
UILogger 通过 CocoaPods 提供。要安装
它,只需将以下行添加到 Podfile 中
pod 'UILogger'
待办事项
UILogTitle
协议及其对 UIViewController
、UIButton
、UICollectionViewCell
的扩展,以便提供有意义的标题Dan Pashchenko https://ios-engineer.com
UILogger 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。