将CFReadStreamRef转换/转换为NSInputStream(iOS5) [英] Convert/cast CFReadStreamRef to NSInputStream (iOS5)

查看:589
本文介绍了将CFReadStreamRef转换/转换为NSInputStream(iOS5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的应用移植到iOS5。我通过CFSockets使用TCP连接到服务器。我现在的问题是从CFReadStreamRef到NSInputStream的转换(强制转换)(与write相同)。使用iOS4,我可以使用免费桥接,但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

代码:

        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吗?
感谢您的任何提示!

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);

这篇关于将CFReadStreamRef转换/转换为NSInputStream(iOS5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆