NSURLConnection-Swizzled 1.0

NSURLConnection-Swizzled 1.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最新发布2014年12月

Rui Peres维护。



  • 作者:
  • R. Peres

NSURLConnection+Swizzled


该分类用于“记录 curl 命令行提示,以进行调试”。该分类受到了 Mugunth Kumar 的 NSMutableURLRequest+MKCurlAdditions 的启发,您可以在Mugunth Kumar处找到它,您可以在这里找到它这里。它还会打印堆栈跟踪,以便您了解调用来源。

这对于了解调用的类型以及它们是如何创建的非常有用,例如,您的 URL 是如何创建的。

不要忘了在生产代码中禁用它。这只是为了调试


需求

包含库

  • libobjc.dylib

并可导入您希望使用的分类

  • #import "NSURLConnection+Swizzled.h"

将 NSURLConnection+Swizzled 添加到项目中

只需将这两个文件添加到您的项目中(NSURLConnection+Swizzled.hNSURLConnection+Swizzled.m)。


使用方法

在建立远程连接之前,您可以调用 SWIZZ_IT,在完成后调用 UN_SWIZZ_IT。例如

SWIZZ_IT
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"www.google.com"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *as, NSData *a, NSError *ads)
{
   NSLog(@"blah blah");
}];

UN_SWIZZ_IT

这将输出

2013-07-27 01:33:24.366 Testing[12197:c07] ------------------------------  Stack trace  ---------------------------------------
2013-07-27 01:33:24.369 Testing[12197:c07] 0 Testing +[NSURLConnection(Swizzled) outputStackTrace] + 71
2013-07-27 01:33:24.370 Testing[12197:c07] 1 Testing +[NSURLConnection(Swizzled) operateRequest:] + 69
2013-07-27 01:33:24.370 Testing[12197:c07] 2 Testing +[NSURLConnection(Swizzled) swizzSendAsynchronousRequest:queue:completionHandler:] + 132
2013-07-27 01:33:24.371 Testing[12197:c07] 3 Testing -[APViewController viewDidLoad] + 296
2013-07-27 01:33:24.371 Testing[12197:c07] 4 UIKit -[UIViewController loadViewIfRequired] + 536
2013-07-27 01:33:24.371 Testing[12197:c07] 5 UIKit -[UIViewController view] + 33
2013-07-27 01:33:24.372 Testing[12197:c07] 6 UIKit -[UIWindow addRootViewControllerViewIfPossible] + 66
2013-07-27 01:33:24.372 Testing[12197:c07] 7 UIKit -[UIWindow _setHidden:forced:] + 368
2013-07-27 01:33:24.373 Testing[12197:c07] 8 UIKit -[UIWindow _orderFrontWithoutMakingKey] + 49
2013-07-27 01:33:24.373 Testing[12197:c07] 9 UIKit -[UIWindowAccessibility(SafeCategory) _orderFrontWithoutMakingKey] + 77
2013-07-27 01:33:24.374 Testing[12197:c07] 10 UIKit -[UIWindow makeKeyAndVisible] + 65
2013-07-27 01:33:24.374 Testing[12197:c07] 11 Testing -[APAppDelegate application:didFinishLaunchingWithOptions:] + 661
2013-07-27 01:33:24.375 Testing[12197:c07] 12 UIKit -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 266
2013-07-27 01:33:24.375 Testing[12197:c07] 13 UIKit -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1248
2013-07-27 01:33:24.375 Testing[12197:c07] 14 UIKit -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 805
2013-07-27 01:33:24.376 Testing[12197:c07] 15 UIKit -[UIApplication handleEvent:withNewEvent:] + 1022
2013-07-27 01:33:24.376 Testing[12197:c07] 16 UIKit -[UIApplication sendEvent:] + 85
2013-07-27 01:33:24.377 Testing[12197:c07] 17 UIKit _UIApplicationHandleEvent + 9874
2013-07-27 01:33:24.377 Testing[12197:c07] 18 GraphicsServices _PurpleEventCallback + 339
2013-07-27 01:33:24.378 Testing[12197:c07] 19 GraphicsServices PurpleEventCallback + 46
2013-07-27 01:33:24.378 Testing[12197:c07] 20 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
2013-07-27 01:33:24.379 Testing[12197:c07] 21 CoreFoundation __CFRunLoopDoSource1 + 146
2013-07-27 01:33:24.379 Testing[12197:c07] 22 CoreFoundation __CFRunLoopRun + 2118
2013-07-27 01:33:24.380 Testing[12197:c07] 23 CoreFoundation CFRunLoopRunSpecific + 276
2013-07-27 01:33:24.380 Testing[12197:c07] 24 CoreFoundation CFRunLoopRunInMode + 123
2013-07-27 01:33:24.381 Testing[12197:c07] 25 UIKit -[UIApplication _run] + 774
2013-07-27 01:33:24.381 Testing[12197:c07] 26 UIKit UIApplicationMain + 1211
2013-07-27 01:33:24.382 Testing[12197:c07] 27 Testing main + 141
2013-07-27 01:33:24.382 Testing[12197:c07] 28 Testing start + 53
2013-07-27 01:33:24.383 Testing[12197:c07] ----------------------------------------------------------------------------
2013-07-27 01:33:24.384 Testing[12197:c07] Saturday, July 27, 2013, 1:33:24 AM Western European Summer Time
Request
-------
curl -X GET 'www.google.com'

如果您对堆栈跟踪不满,请勿使用: STOP_STACKTRACE_SWIZZ

如果您希望在应用程序整个运行期间接收信息,则在 applicationDidFinishLaunching 上调用 SWIZZ_IT,并不要使用 UN_SWIZZ_IT


许可证

该代码是根据 MIT 许可证的条款和条件分发的。