我试图使用NSURLProtocol记录Swift 2.3项目中的所有请求。然而并非所有的URL请求都被记录。具体而言,所有Alamofire请求都没有被记录。Swift - 在mac应用程序中记录所有请求
示例代码
class AppDelegate: NSObject, NSApplicationDelegate{
func applicationDidFinishLaunching(aNotification: NSNotification) {
NSURLProtocol.registerClass(TestURLProtocol)
Alamofire.request(.GET, SomeURL).responseSwiftyJSON({ (request, response, json, error) in })
}
}
class TestURLProtocol: NSURLProtocol {
override class func canInitWithRequest(request: NSURLRequest) -> Bool {
print("request \(request.URL!)") // never called
return false
}
}
我试图从这个响应中使用方法,它没有工作。 http://stackoverflow.com/a/28720198/1449607 – datinc
是的,但你必须在会话管理器中注入配置,然后使用它来代替'Alamofire.request' – Alistra
我正在尝试监视第三方服务。我正在寻找一种解决方案,可以让我监控这些请求,而无需修改代码。 – datinc