Quantcast
Channel: 睿论坛 - 最新话题
Viewing all articles
Browse latest Browse all 5731

Hook NSURLSession dataTaskWithRequest:completionHandler 中替换block 导致崩溃

$
0
0

@694663906 wrote:

代码如下 hook dataTaskWithRequest:completionHandler:
当 block 为nil时 如果传入自己的block 会导致程序崩溃。
后来找到了这个帖子
https://juejin.im/post/5a9e20b3f265da239866c4c9
hook了safari的WKNetworkSessionDelegate
拦截了 dataTaskWithRequest:completionHandler:block 为nil时 返回的数据

查找了论坛里类似的帖子 都没有解释原因 很想知道为什么会这样
崩溃日志也没找到什么
请大哥们赐教 不胜感激

%hook NSURLSession

  • (id)dataTaskWithRequest:(id)arg1 completionHandler:(void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))arg2{

NSLog(@“hook===dataTaskWithRequest==%@==%@”,arg1,arg2);

void (^b1)(NSData*,NSURLResponse*,NSError*) = ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

NSLog(@"hook==%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
  //执行原来的block
    arg2(data,response,error);

};
if(arg2){
%orig(arg1,b1);
}else{
//这里如果吧自己的block 传入会崩溃
%orig(arg1,nil);
}

}

%end

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 5731

Trending Articles