无法调动NSOutputStream的写:MaxLength:

时间:2014-11-29 07:16:59

标签: ios swizzling nsoutputstream

在实际写入NSOutputStream之前,我需要编写自定义数据。

为了使swizzling代码执行,我创建了一个类别NSOutputStream(SwizzleWrite),其中包含以下内容:

SEL originalSelector = @selector(write:maxLength:);
SEL swizzledSelector = @selector(swizzledWrite:maxLength:);

Method originalMethod = class_getInstanceMethod([NSOutputStream class], originalSelector);
Method swizzledMethod = class_getInstanceMethod([self class], swizzledSelector);

method_exchangeImplementations(originalMethod, swizzledMethod);

然后我创建了Inout&输出流: CFStreamCreatePairWithSocketToCFHost(kCFAllocatorDefault,hostRef,80,& readStream,& writeStream);

inputStream = (__bridge_transfer NSInputStream *)readStream;
outputStream = (__bridge_transfer NSOutputStream *)writeStream;
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];

但是现在当控件到达handleEvent:delegate时,特别是: [outputStream write:rawstring maxLength:sizeof(rawstring)]; ,我在swizzledWrite上没有得到它:maxLength:

我在这里做错了什么?

PS:我已经读到混合Apple方法不适合Appstore,但我也读过它们被接受的案例。

1 个答案:

答案 0 :(得分:0)

为什么你觉得调酒是最好的选择?对我来说就像一个子类会好得多。有关子类化流的一些棘手的部分,但看看here

如果您决心进行调情工作,是否设置了断点并确保您的调节选择器不是零?如果签名有点不对,可能会发生