Comments (9)
from ios-monitor-platform.
@hcl416029105 我先看看,晚上给你答复。
from ios-monitor-platform.
如果不用AFHTTPSessionManager,直接用原生的NSURLSession,没有问题:
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[[NSOperationQueue alloc] init]];
NSURLSessionTask *task = [session dataTaskWithURL:[NSURL URLWithString:@"https://hcz-static.pingan.com.cn/fuelCard/fuelCard.zip"]];
[task resume];
这种可以正常调用。
好的,非常感谢你的解答
from ios-monitor-platform.
@hcl416029105 多谢提供的信息,我这边看了下,用 AFNetworking 出问题的原因是在 CFNetwork -[__NSCFURLLocalSessionConnection initWithTask:delegate:delegateQueue:]
方法中会调用 __NSURLSessionLocal
的 can_delegate_task_willSendRequestForEstablishedConnection
方法,而这个方法中会执行下列方法:
[delegate respondsToSelector:@selector(URLSession:task:_willSendRequestForEstablishedConnection:completionHandler:)]
delegate
此时已经是你的 NSURLDelegateProxy
对象,他无法响应 respondsToSelector
,所以会走消息转发的流程中,也就会走到 NSURLDelegateProxy
对象 的 methodSignatureForSelector
。
- (nullable NSMethodSignature *)methodSignatureForSelector:(SEL)sel
{
NSMethodSignature *methodSignature = nil;
if ( [self.proxyTarget respondsToSelector:sel]) {
methodSignature = [self.proxyTarget methodSignatureForSelector:sel];
}
return methodSignature;
}
但是因为你的 proxyTarget
在 initWithTarget
被赋值为 AFHTTPSessionManager
对象,而且这个属性为弱引用,而执行到 methodSignatureForSelector
时,AFHTTPSessionManager
对象已经被释放,所以这里 return 的 methodSignature
实际为 nil,导致消息转发流程失败,也就有了下面的输出:
*** NSForwarding: warning: object %p of class '%s' does not implement doesNotRecognizeSelector: -- abort
将属性改为 strong,发现问题已经没有了。
@property(nonatomic, strong) id proxyTarget;
当然你可能会问为什么直接使用 NSURLSession
的 API 无此问题。
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[[NSOperationQueue alloc] init]];
NSURLSessionTask *task = [session dataTaskWithURL:[NSURL URLWithString:@"https://hcz-static.pingan.com.cn/fuelCard/fuelCard.zip"]];
[task resume];
事实上使用 NSURLSession
的 API 和 AF 在 CFNetwork 层都会走上面的那段逻辑,但是由于sessionWithConfiguration:delegate:delegateQueue
方法的入参 delegate 恰好是一个强引用的对象,比如我这里可能是一个 ViewController
,所以即使 proxy 那边是弱引用,执行到 methodSignatureForSelector
能够正常返回方法签名对象,消息转发的流程得以正常执行,所以这种场景无此问题。
具体你可以在自己项目中调试来验证,建议在 NSURLDelegateProxy
的 methodSignatureForSelector
方法下断点来验证。
from ios-monitor-platform.
@hcl416029105 另外关于网络监控这块可以看下我的另外一篇文章揭秘 APM iOS SDK 的核心技术,文章对听云的网络监控实现进行了一些探索,希望能对你有所帮助。
from ios-monitor-platform.
网络监控搞复杂了,不用各种swizze,各种hook,直接取getifaddrs获取的数据
from ios-monitor-platform.
@hcl416029105 getifaddrs()
函数拿到的 ifaddrs
struct 最多也是本地地址的信息吧,类似 Local IP 这些,网络监控要获取到的远远不止这个。
from ios-monitor-platform.
from ios-monitor-platform.
如果强引用的话 会不会引起对象释放不了的问题吗
同问
from ios-monitor-platform.
Related Issues (20)
- API 图形化 HOT 3
- 新增流量监控的实现方式
- resident_size 大小问题 HOT 2
- 有webview内的h5性能监控方面的资料吗 HOT 2
- 楼主能不能给一个系统CPU的demo HOT 1
- 弱弱问一句,楼主博客文章的用的配色是什么方案,文章看下来很舒服
- 如何使用NSProxy
- ReadMe中的获取应用占用内存方法错误
- 你好,你这边的数据可视化是怎么做的呢
- 总结较全面了,GPU 也可以加一下
- 关于冷热启动的概念描述不对
- 注意文章引用问题
- 有源码借鉴吗
- 有swift版本吗 谢谢 HOT 1
- 使用CFReadStreamCreateForHTTPRequest 截取网络请求,无果!
- Readme里关于`vm_statistics_data_t`的描述
- Xcode13 thread_info failed
- 发现获取cpu频率的函数iOS上并不能正常工作 HOT 50
- 网络监控里面为什么不直接hook socket HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ios-monitor-platform.