开发者

Problem with "CFDataRef".

I have a problem with "CFDataRef. I get the "data" field from a "kCFSocketDataCallBack. "data" should correspond to a string received on the socket. How do I convert, for example, in a开发者_JAVA技巧 NSString so I can put my text in a textbox??

Thank you very much

 static void
 AcceptDataCallback(CFSocketRef s,
 CFSocketCallBackType type, CFDataRef
 address, const void *data, void *info)
 {

 //my code for the textBox

 }


You could first try converting to NSData by casting it:

NSData * someData = (NSData*)address;

Then convert the NSData to NSString:

NSString * someString = [[NSString alloc] initWithData:someData encoding:NSASCIIStringEncoding];

Or do it all at once:

NSString * someString = [[NSString alloc] initWithData:(NSData*)address encoding:NSASCIIStringEncoding];

You may have to mess around with the encoding.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜