How can an iPhone access another non-iPhone device over wireless or Bluetooth?
Asked Answered
A

3

27

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 Stack Overflow questions, like Can the iPhone 3.0 SDK provide full access to Bluetooth devices (headsets)? 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, Peer-to-Peer Connectivity, it mentions connecting two iPhones, not an iPhone to another Bluetooth device. Then there are articles like iPhone SDK focus: Bluetooth enhancements 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

Another Stack Overflow question, GameKit in iPhone SDK 3.0, mentions Bonjour, and the Apple documentation for Bonjour talks about connecting to Bonjour devices, but can an iPhone connect to any Bonjour device? Does it have to have a Wi-Fi 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.

Alphabetize answered 30/6, 2009 at 19:14 Comment(0)
B
12

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 Wi-Fi, 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.

Barcelona answered 30/6, 2009 at 22:16 Comment(3)
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?Alphabetize
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.Barcelona
No, the iPhone doesn't have to be on a wifi network: it will use any network device available on the system - in particular: Bluetooth. For iOS6 onwards, Apple disables BT lookup for Bonjour by default (Apple's explanation (excuse) for doing this breaking-change, and the official workaround instructions developer.apple.com/library/ios/qa/qa1753/_index.html#//…)Cariecaries
T
1

You can use NSStream for opening IPv4/IPv6 sockets on the iPhone. The devices to which you're connecting do not have to be iPhones or use Wi-Fi 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.

Theo answered 30/6, 2009 at 19:39 Comment(4)
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.Alphabetize
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!Theo
You might want to invest time in the External Accessory framework, released with 3.0Theo
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?Alphabetize
F
0

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 (that is, play, pause, 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.

See also Apple's page on iPhone OS accessories.

Fulcrum answered 30/6, 2009 at 19:42 Comment(2)
Those are all "Made for iPhone" devices. Is that the only way to connect to a Bluetooth device? Also, according to the Apple documentation, Bluetooth networking is not supported on the original iPhone or the first-generation iPod Touch. It is also not supported in Simulator.Alphabetize
That link to iPhone OS accessories appears to have gone bad.Ryley

© 2022 - 2024 — McMap. All rights reserved.