P.B*_*P.B 1 implementation exchange-server objective-c-runtime ios-simulator
我目前正在尝试使用http://sudzc.com/中的一些生成代码. 这段代码并不完全适合我的Web服务,因此我尝试将类别添加到一些生成的类中,并使用原始类替换它们的实现来自"objc/runtime.h"的method_exchangeImplementations.(我可以直接修改生成的代码,但我想避免它).
这是我在MyAppAppDelegate中执行的代码 - applicationDidFinishLaunching方法
Class theClass = [CBMayaIPhoneUser class];
Method originalMethod = class_getClassMethod(theClass, @selector(initWithNode:));
Method categoryMethod = class_getClassMethod(theClass, @selector(initWithAllStringNode:));
method_exchangeImplementations(originalMethod, categoryMethod);
theClass = [Soap class];
originalMethod = class_getClassMethod(theClass, @selector(getNodeValue:withName:));
categoryMethod = class_getClassMethod(theClass, @selector(getHrefNodeValue:withName:));
method_exchangeImplementations(originalMethod, categoryMethod);
theClass = [SoapRequest class];
originalMethod = class_getClassMethod(theClass, @selector(send));
categoryMethod = class_getClassMethod(theClass, @selector(sendIgnoringCertificate));
method_exchangeImplementations(originalMethod, categoryMethod);
originalMethod = class_getClassMethod(theClass, @selector(connectionDidFinishLoading:));
categoryMethod = class_getClassMethod(theClass, @selector(connectionDidFinishLoadingAndSentBody:));
method_exchangeImplementations(originalMethod, categoryMethod);
Run Code Online (Sandbox Code Playgroud)
正如我的问题所述,几乎所有这些class_getClassMethod都返回nil ...我使用了调试器,所以我知道'theClass'是正确设置的.找到的唯一方法是Soap类,它们都是类级(+)方法.但是从网上的各种例子中我得出的结论是,它也适用于其他人......
以下是MyAppAppDelegate.m的包含:
#import "MyAppAppDelegate.h"
#import "RootViewController.h"
#import "MyGlobalVariables.h"
#import "MyWebServiceExample.h"
#import "Soap+Href.h"
#import "SoapRequest+Certificate.h"
#import "CBMayaIPhoneUser+AllString.h"
#import "objc/runtime.h"
Run Code Online (Sandbox Code Playgroud)
我也测试了我的类别并且它们工作,我可以从'originalClass'对象调用类别方法.
我想我做错了什么,但我看不出是什么......或者class_getClassMethod确实只能用于类级方法?
何和最后一件事,我在模拟器上开发,而不是设备:)
欢迎任何想法!
谢谢
PB
没关系,我的错误,class_getClassMethod确实应该只适用于类级方法(顾名思义)
例如方法,使用... class_getInstanceMethod ... :)
抱歉,添麻烦了
PB
| 归档时间: |
|
| 查看次数: |
2142 次 |
| 最近记录: |