可以挂钩+ [NSURLSession sessionWithConfiguration:delegate:delegateQueue:],但调用%orig会给出“无法识别的选择器", [英] Can hook +[NSURLSession sessionWithConfiguration:delegate:delegateQueue:] but calling %orig gives "unrecognized selector"

查看:160
本文介绍了可以挂钩+ [NSURLSession sessionWithConfiguration:delegate:delegateQueue:],但调用%orig会给出“无法识别的选择器",的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我感到困惑.我已经在NSURLConnection上钩上了类方法,没有问题,但是我陷在+[NSURLSession sessionWithConfiguration:delegate:delegateQueue:]上.

This is baffling me. I have hooked class methods on NSURLConnection with no problems but I am stuck with +[NSURLSession sessionWithConfiguration:delegate:delegateQueue:].

我什至尝试使用class_copyMethodList (object_getClass([NSURLSession class]), &count);记录所有类方法,而该类方法实际上在那儿: sessionWithConfiguration:delegate:delegateQueue: initialize

I even tried logging all the class methods with class_copyMethodList (object_getClass([NSURLSession class]), &count); and the class method is actually there: sessionWithConfiguration:delegate:delegateQueue: initialize

奇怪的是,钩子确实被调用了,所以我认为我们做对了.调用%orig()并仅将参数向下传递即可:

And the weird thing is the hook does get called so I think we got it right. Calling %orig() and just passing the parameters down yields:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSURLSession sessionWithConfiguration:delegate:delegateQueue:]: unrecognized selector sent to class 0x1919932b8'

这是钩子:

+ (NSURLSession *)sessionWithConfiguration:(NSURLSessionConfiguration *)configuration
                                  delegate:(id<NSURLSessionDelegate>)delegate
                             delegateQueue:(NSOperationQueue *)queue
{

    NSURLSession *origResult = %orig(configuration, delegate, queue);

    return origResult;
}

我想念什么吗?

设置详细信息: rpetrich的Theos Mac OS X 10.9.5 iPad Air 1 iOS 7.1.2

Setup details: rpetrich's Theos Mac OS X 10.9.5 iPad Air 1 iOS 7.1.2

推荐答案

此处的问题与

The problem here is related to NSURLSession being a class cluster. While the code in OP successfully hooked the class method, %orig needs to call on the real class name. So to make it work, this hook has to be placed under %hook __NSCFURLSession. The real class name might be different for your case.

这篇关于可以挂钩+ [NSURLSession sessionWithConfiguration:delegate:delegateQueue:],但调用%orig会给出“无法识别的选择器",的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆