将CFReadStreamRef转换/转换为NSInputStream(iOS5)

时间:2011-06-17 11:29:26

标签: network-programming release counting ios5

我正在尝试将我的应用移植到iOS5。我通过CFSockets使用TCP连接到服务器。我现在的问题是从CFReadStreamRef到NSInputStream的转换(强制转换)(与write相同)。使用iOS4,我可以使用免费桥接,但是使用iOS5的自动引用计数,这是不可能的。这就是我得到的:

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

代码:

        CFReadStreamRef readStream;
        CFWriteStreamRef writeStream;

        CFStringRef strRef = CFStringCreateWithCString(NULL,
              [urlStr UTF8String],
              NSUTF8StringEncoding);
        CFStreamCreatePairWithSocketToHost(NULL,
           strRef,
           4444,
           &readStream,
           &writeStream);



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

是否有另一种方法可以将套接字输出/输入NSStream? 谢谢你的提示!

1 个答案:

答案 0 :(得分:2)

管理免费电话桥接非常清楚地表明您应该使用以下内容:

NSInputStream *iStream = objc_unretainedObject(readStream);