由于软件开发的特点,调试和测试iOS应用程序可能是一项相当长的任务。《Harlow》工具提供了丰富的有关分析、错误、日志记录、网络和UITesting的信息,以简化此过程。
目录
作者
Tal Zion [email protected]
安装
pod 'Harlow', :configurations => ['Debug'] # Make sure to only use Harlow for development only.
使用方法
#if DEBUG
import Harlow
#endif
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
#if DEBUG
lazy var debugger: Harlow = Harlow()
#endif
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
#if DEBUG
debugger.isEnabled = true
#endif
}
}
其他选项
debugger.isDebuggingDataPersistenceEneabled = true /// Enables local data persistance
debugger.enabledServices: [Service] = [.logs, .errors] /// The services you would like to enable. Default is se to `allCases`
debugger.tintColor = .red /// Change the tint color
debugger.errorCodesExceptions = [4097] /// Add error code exceptions
debugger.isShakeEnabled = true // Defaults to `true`. When this is `true`, shaking the device will enable/disable the Debugger
debugger.isEnabled = true
添加日志
分析
选项 1.
设置您的跟踪有效载荷
public func payload() -> [String:String] {
var payload: [String:String] = ["eventName": eventName]
if let itemId = itemId {
payload["itemId"] = itemId
}
if let category = category {
payload["category"] = category
}
if let contentType = contentType {
payload["contentType"] = contentType
}
if let screenName = screenName {
payload["screenName"] = screenName
}
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
payload["createdAt"] = dateFormatter.string(from: Date())
return payload
}
发布到
func post(_ payload: [String:String]) {
let notificationCentre = NotificationCenter.default
let notification = Notification.init(name: Notification.Name(rawValue: "io.stanwood.debugger.didReceiveAnalyticsItem"), object: nil, userInfo: payload)
notificationCentre.post(notification)
}
选项 2.
使用 StanwoodAnalytics 作为您的跟踪框架
#if DEBUG
analyticsBuilder = analyticsBuilder.setDebuggerNotifications(enabled: true)
#endif
网络
Harlow
默认与 URLSessiosn.shared
一起工作,请求将被免费记录。您还可以注册自定义配置
let configuration = URLSessionConfiguration.waitsForConnectivity
debugger.regsiter(custom: configuration)
/// Use with URLSession || any networking libraries such as Alamofire and Moya
let session = URLSession(configuration: configuration)
错误
Harlow
默认会记录 NSError
。要添加日志异常
debugger.errorCodesExceptions = [4097] /// Add error code exceptions
日志
Harlow
默认会记录 print
和 debugPrint
。
配置
- 创建一个新的
Bridging-Header
文件并添加-DEBUG
后缀
- 导入
Harlow
@import Harlow;
注意:确保在主头文件中添加任何其他导入的库
- 在构建设置的相关配置中设置
Bridging-Header-DEBUG.h
。
崩溃
Harlow
默认会记录 Signal
和 NSException
崩溃。
许可证
Harlow 遵循 MIT 许可协议。更多信息请参阅 LICENSE 文件。
更新日志
每个Harlow发布的简要总结可以在变更日志中找到。