- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request
completionHandler:(void (^)(NSData *data,NSURLResponse *response,NSError *error))completionHandler 这个completionHandler应该如何hook?
正向问题 下一位
如何讲?您觉得是很简单吗?
%hook NSURLSession
-
(NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request
completionHandler:(void (^)(NSData *data,NSURLResponse *response,NSError *error))completionHandler {void (^replacedCompletion)(NSData *,NSURLResponse *,NSError *) = ^void(NSData *newData,
NSURLResponse *newResponse,
NSError *newError) {NSString *responseString = [[NSString alloc] initWithData:newData encoding:NSUTF8StringEncoding]; NSLog(@"responseString %@",responseString); completionHandler(newData, newResponse, newError); }; return %orig(request, replacedCompletion);
}
%end
hi 这个似乎没那么简单
%hook NSURLSession
-
(NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request
completionHandler:(void (^)(NSData *data,NSURLResponse *response,NSError *error))completionHandler {void (^replacedCompletion)(NSData *,NSURLResponse *,NSError *) = ^void(NSData *newData,
NSURLResponse *newResponse,
NSError *newError) {NSString *responseString = [[NSString alloc] initWithData:newData encoding:NSUTF8StringEncoding]; NSLog(@"responseString %@",responseString); completionHandler(newData, newResponse, newError); }; return %orig(request, replacedCompletion);
}
%end
这么hook 有问题,知道哪里错了吗?
什么问题
NSLog(@“responseString %@”,responseString);
没有打印?
在iphone6上闪退!completionHandler可能已经释放了
先copy
试过了 不闪退了 但是程序执行不下去了
你猜!!!!!!