开发者

Convert/cast CFReadStreamRef to NSInputStream (iOS5)

I am trying to port my app to iOS5. I am using a TCP connection to a server via CFSockets. My problem now is the conversion (cast) from CFReadStreamRef to NSInputStream (same with write). With iOS4 I could use the toll-free bridging, but with automatic reference counting of iOS5 this isn't possible anymore. This is what I get:

error: Automatic Reference Counting Issue: Cast to 'NSInputStream *' of a non-Objective-C to an Objective-C pointer is disallowed with Automatic Reference Counting

Code:

        CFReadStreamRef readStream;
        CFWriteStreamRef writeStream;

        CFStringRef strRef = CFStringCreateWithCString(N开发者_如何转开发ULL,
              [urlStr UTF8String],
              NSUTF8StringEncoding);
        CFStreamCreatePairWithSocketToHost(NULL,
           strRef,
           4444,
           &readStream,
           &writeStream);



        NSInputStream *iStream = (NSInputStream *)readStream;
        NSOutputStream *oStream = (NSOutputStream *)writeStream;         

Is there another way to pipe the socket out/input into an NSStream? Thanks for any hint!


Managing Toll-Free Bridging states very clearly that you should use something like this:

NSInputStream *iStream = objc_unretainedObject(readStream);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜