views:

6396

answers:

3

I'm trying to figure out if an iPhone can connect to another non-iPhone device over wireless or bluetooth and have seen conflicting information. Much of what I've found was before version 3.0 of the SDK came out, when it certainly wasn't possible. Looking at questions like this mention you can't connect to an arbitrary device unless if it's part of the "Works for iPhone" device. Do I need hardware that is part of this program? Looking through the Apple documentation, it mentions connecting two iPhones, not an iPhone to another Bluetooth device. Then there are articles like this that includes this quote

...and with the newly-announced "standard support" should allow file transfer between the iPhone and a computer, as well as between nearby iPhones

Other questions mention Bonjour, and the Apple documentation talk about connecting to Bonjour devices, but can an iPhone connect to any Bonjour device? Does it have to have a wifi connection, or can it use Bluetooth?

Even if I could use Bluetooth to connect to another device, it won't be available on first generation iPhones and iTouches, I believe. Is that correct? I'm thinking of an iPhone application that would need to communicate with other non-iPhone devices in the area, probably using Bluetooth, but possibly a direct wireless connection. What are the possibilities and limitations of this approach? Is it not possible to have an iPhone connect to an arbitrary Bluetooth device? Does the other device have to be on a wireless Bonjour network that? I'm trying to figure out if it's even possible for this to work or if it's not worth the effort.

+1  A: 

You are asking a lot of questions for one post... You can use NSStream for opening inet4/6 sockets on the iPhone. The devices to which you're connecting do not have to be iPhones or use Wifi necessarily. Because of how network communication protocols are laid out, you simply don't have to care what kind of device your iphone is communicating with.

Bonjour, on the other hand, uses NSStream internally. It's basically a nifty little wrapper which allows for auto-discovery. You need the Bonjour protocol installed on all devices which you want to participate in the auto-discovery process. There is even an implementation for Windows.

Andrei Tanasescu
Sorry for the many questions - the underlying issue is can the iPhone connect to an arbitrary device. For example, if the app is for reading electric meters, I would want to be able to walk into a room and connect to any given meter without knowing anything about a specific meter (Bluetooth ID, IP address, etc). It seems that would be possible with Bonjour (if the meters supported the protocol), but not Bluetooth. Is that correct? To connect to another Bonjour device, would the iPhone need be be on a wireless network or connected via Bluetooth? It doesn't seem so.
Tai Squared
If I understand correctly, you are asking how you might get a list of all bluetooth meters within range of your iphone? I do know that Bluetoth devices can auto-discover each other, yet I do not think they use Bonjour(Zeroconf) to do it. I am pretty sure the protocol itself is bluetooth specific. It sounds like a pretty cool project!
Andrei Tanasescu
You might want to invest time in the External Accessory framework, released with 3.0
Andrei Tanasescu
Yes, I want to find all Bluetooth devices in range and send data back and forth. Based on the Apple documentation, it appears you can only connect to other iPhones, but you're saying it can auto-discover other devices. Is that true?
Tai Squared
A: 

As part of the iPhone OS 3.0 SDK apple announced the ability to control hardware accessories through either bluetooth or the dock connector. The dock connector supports standard protocols (i.e. play, plause, etc...) as well as any custom protocols the developer wants to implement. As far as connecting via bluetooth, you can talk to other iPhones or other devices. For example you can use stereo bluetooth to connect compatible Bluetooth stereo headphones, car kits, or other accessories.

As far as what devices support bluetooth communication, everything except the first generation iPod Touch should be okay.

Here is the link to Apple's page on iPhone OS accesories.

zPesk
Those are all "Made for iPhone" devices. Is that the only way to connect to a Bluetooth device? Also, according to the [Apple documentation](http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/GameKit_Guide/GameKitConcepts/GameKitConcepts.html#//apple_ref/doc/uid/TP40008304-CH100-SW1), Bluetooth networking is not supported on the original iPhone or the first-generation iPod Touch. It is also not supported in Simulator.
Tai Squared
+2  A: 

The only way to communicate with other Bluetooth devices via the External Accessory framework in iPhone OS 3.0 is if they are in the Made for iPod accessory program. Even though they communicate through standard Bluetooth connections, accessories need special hardware in order to process the data stream coming from the iPhone / iPod touch. Unfortunately, this means that your idea of communicating with generic Bluetooth devices won't work on iPhone OS 3.0.

If the devices you want to talk to are Bonjour-discoverable via WiFi, they don't need to be part of the Made for iPod program. However, that doesn't sound like your case.

Third-party developers in the near future may produce dongles that connect through the 30-pin dock port and give access to existing Bluetooth devices. If these developers opened up their communication protocol, that might enable your goal of communicating with these devices.

Brad Larson
Thanks for the info - the more I read, the more I thought Bluetooth wouldn't be a viable option unless if the devices are in the Made for iPod program. As for Bonjour, does the iPhone/iTouch have to be on a wireless network to discover a Bonjour device? Are there any range limitations to Bonjour, or is it just what range the other device can broadcast to?
Tai Squared
Bonjour is simply a discovery protocol, so its range is whatever your network's range is. It is intended for use on a local area network, so that pretty much means that the iPhone must be on a WiFi network. The devices themselves could be hardwired or connected to the network by other means, though.
Brad Larson