-->

[iPhone]: How send output stream via wireless netw

2020-08-04 05:59发布

问题:

I want to write an app for a certain type of printer to print some text via wifi for iPhone. iPhone can join an existing wifi network by the Settings app, but how to create an output stream for the network so that the app can use it to send command to printer?

I mean the wifi connection is set up already, how to get something like NSOutputStream to write data to it?

回答1:

I'm not sure what protocal you wifi printer uses (or wifi printers in general) but you are in luck, iPhone apps can be written to interact with the network. You could use the low level BSD Unix style network socket calls, but luckily`you don't have to. CFNetwork will become your friend here.

CFNetwork CFNetwork is a framework in the Core Services framework that provides a library of abstractions for network protocols. These abstractions make it easy to perform a variety of network tasks including working with streams.

I recommend reading the CFNetwork Programming Guide at: http://developer.apple.com/documentation/Networking/Conceptual/CFNetwork/CFStreamTasks/CFStreamTasks.html#//apple_ref/doc/uid/TP30001132-CH6-SW1