NSOutputStream の実際の書き込みが発生する前に、カスタム データを書き込む必要があります。
スウィズリング コードを実行するために、以下を含むカテゴリ 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 & Output ストリームを作成します: 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 に適していないことを読みましたが、それらが受け入れられているケースも読みました。