Bluetooth vs. Wifi for iPhone data transfer - iphone

I'm working on adding sharing support to my iPhone app. Right now, I'm using Bonjour to create plain TCP connections over a wifi network. This works great, except that it turns out that many wifi networks in the real world (for example, those at Starbucks and other chains) forbid Bonjour publishing and discovery over their networks.
So that limits the usefulness of sharing, since one of the use cases we imagined was that people could bump into each other where wifi was available and seamlessly share data with each other.
Is Bluetooth a viable alternative for this? We're sending large amounts of data (PNG images) over the wire, so latency and throughput might be one issue.
(I'm also interested in any other ways to make it easy to transfer data between two iPhone apps)

Related

iOS bluetooth data transfer, Gamekit or Bonjour

I'm looking around to find the appropriate technology to implement an app that I've in mind.
Basically I am using bluetooth to estabilish a connection trhrough 2 iOS devices. In the first part of communication I only send messages, and everything works ok.
In the second part i would like to permit the user to share a video file; let's assume, for example, that the video file is 20 MB.
Now, what's the best option to transfer this large data through the 2 devices?
Can I use GameKit and split the data in small packet? It'll take a reasonable amount of time?
Or it's better to use Bonjour and wait that until the user'll be under the same wifi network or create a wifi network through the 2 devices?
Thanks in advance
In case someone else (like me) stumbles upon this question, I'll share my experience:
Bluetooth
Pros: You don't need wifi
Cons:
Apple only allows you to access the BLE interface, which is a lot slower than regular bluetooth. I tried this and it takes around 5 minutes to transfer 1 MB of data. Also, you need to chop your data into chunks of ~20 Bytes and make sure the files are received correctly on the other side.
GameKit
I haven't actually tried it, but it seems GK is fine to send small text messages (since it is designed for this), however sending larger files will still be pretty slow. Also, you can only connect 8 devices simultaneously.
Bonjour and Wifi
Pros: This is as fast as it gets. You can send reasonably sized files (a few MB) within a few seconds.
Cons: You need to be in the same wifi network.
Using a remote server
Pros: Assuming you have a decent internet connection it's reasonably fast and you are not depending on wifi (if you have 3G/LTE).
As it turns out this is pretty easy when you use a Backend-as-a-Service provider like Parse.
Cons: Well, you're gonna have to write that server software... Your app users probably need a mobile data plan.
I ended up with solution #3, using Bonjour and Wifi, since I didn't want to write server side code. If you want to do this, you need to learn about Socket programming. I suggest using CocoaAsyncSocket which uses TCP so you don't have to make sure you received the file correctly.
Since it is 2016 and Swift can be used in Obj-C projects, you can have a look at my solution, which will spare you almost all of the work: https://github.com/JojoSc/OverTheEther
It allows you to send any kind of object (implementing the NSCoding protocol) to another device.

Measure network traffic programmatically on iPhone

I'm interested in measuring the network traffic for my application. Ideally I would need to separate wireless from 3G network traffic. I can't seem to find any API that gets this information; however I see that there is at least one app in the AppStore that does something close (they actually sum up the traffic for the entire phone).
Any ideas?
I've found one approximate solution: getifaddrs can be used to get statistics on network usage.
One advantage is that it can get separate statistics for Wi-Fi and WWAN interfaces.
A disadvantage is that on multi-tasking devices those interfaces may be used by multiple applications and the statistics are cumulated.
I also was looking for solution and found it here:
iPhone Data Usage Tracking/Monitoring
Please take a look this post, it provides all info that you need.

How quickly can 2 iphones exchange information regarding tilt/position?

I was wondering what amount of time is required to convey information regarding the tilt and position (not gps) of one particular iphone to another. Could 2 iphones send and receive this information simultaneously? What about 3 iphones? I'm interested in an application that is able to simultaneously send and receive and make conditional decisions based on this information received all within a half a second-ish.
Any shot this is possible? If so, is bluetooth or wifi better?
Thanks a ton,
Jake
This is currently not possible without an intermediate server. (Without a jailbreak, which would make it possible, but extremely difficult)
I'm assuming your purpose is gaming, in which case, the latency associated with a trip to a server and back over a cellular data network, is likely to take too long for any satisfactory gaming experience. I don't believe it would be within half a second.
This will be possible via Bluetooth in the upcoming 3.0 iPhone software, but that is still under NDA, so you are not likely to be able to get any reliable performance numbers until it is released. If I were guessing, I would certainly guess that the latency associated with a direct Bluetooth connection would be FAR under half a second.
All you've got as an option right now is Wi-Fi or the Cell Network. If you use Bonjour over Wi-Fi, you'd have latencies in the milliseconds, but all the phones would have to be connected to the same access point. Take a look at the WiTap example.
It is definitely possible, you'd want to connect your peers over WiFi for best performance and reliability, but Bluetooth would be ok as long as your data packets were constrained to small sizes (< 1k). Check out this documentation and sample code to see how to access UIAccelerometer:
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIAccelerometer_Class/Reference/UIAccelerometer.html
http://developer.apple.com/iphone/library/samplecode/AccelerometerGraph/index.html#//apple_ref/doc/uid/DTS40007410
The trick is that the update frequency is controlled in part by the systems needs, so there may be a window (while the system is attempting to update device orientation) wherein your application receives no updates.

What is the range of bluetooth and is it strictly 1:1?

Does anyone know what kind of range can you get from the iPhone
bluetooth? Also, would the connection be strictly one to one? I know you
can choose from a number of peers to connect to but once the connection
is established, it seems you can only transfer data between one peer? So
basically, is it possible to create some kind of "multiplayer" experience?
Just answering the range part of your question...
The 10 meter figure for class 2 devices (of which the iPhone is an example) is very much a guideline.
The range of a Bluetooth device is limited by many real world factors. The 2.4 GHz radio frequency used by Bluetooth is strongly absorbed by water. For example, consider an iPhone connected to a Bluetooth mono headset. If the headset is in one ear and the iPhone is in your trouser pocket on the opposite side of your body, then there's a lot of water between the two devices. This will often cause a significant amount of packet loss in practice (you can hear this in the audio being carried). So, in this case, the range is about one meter.
At the opposite extreme, two class 2 devices separated by nothing more than clear air can get ranges of hundreds of meters.
Other factors that influence things are:
Interference - Lots of things use 2.4 GHz. WiFi, for example can cause problems.
Antenna design - Space and cost constraints often mean that the antenna design is sub-optimal. I don't know how good the iPhone is in this respect.
Walls - Generally walls attenuate Bluetooth signals. However, sometimes they are useful reflectors.
Quality of hardware - Some chips work better than others. Even different firmware revisions of the same chip may perform differently. Different versions of the iPhone probably have (or will have) different chips in them.
Protocol - It is possible to work around poor signal quality with error correction and retransmission. Even if the iPhone SDK forces you to use a particular protocol, careful design of your application can make a difference.
So, in summary, you should probably do some real world tests.
The connection is one-to-one, but you can create an adhoc network with one of the phones acting as the master/coordinator. The other phones would route all their communication through the master/coordinator.
One device can theoretically connect to 7 devices. according to the master-slave role, the device can multiplex between each of them giving the user an impression that you are connected to all of them simultaneously. Bluetooth specification does not stop you from doing that.This is theory.
Now for the iphone, whether it can connect to to more than one device can only be answered by apple or someone who knows the iphone bluetooth API. But I am pretty sure the bluetooth chip inside iphone should be able to connect to more than one device.
Range is essentially going to be good enough for a normal sized room to be covered. It can be longer or shorter depending on environmental circumstances, but remember that bluetooth was created to implement short range connections.
A bluetooth device can be part of a piconet of eight devices, one master and up to seven slaves. The slaves cannot communicate with each other, they must talk through the master, think of a star topology with the master in the center. The iPhone SDK has a GameKit framework that can be used to create the network for multiplayer games. Go to developer.apple.com at look at the GKTank and GKRocket sample code to see how it's used. These games only support two players, but the GameKit framework supports more. Look at the app store and you will see games that have four or more players.
Hope this helps to get started.
Apple iPhone 3G has a Class 2 bluetooth module. Class 2 Bluetooth devices have a communication range of 10 meters.
At a given instance a device can connect to just one device because it follows a master/slave communication model. But still we can perform a multiplexing. So we can virtually connect to more than 1 device and by rapidly changing the connected device.
I found a good article here. It explains bluetooth very well.
According to the my knowledge, multicasting is not impossible with bluetooth. So gaining a multiplayer experience is NOT impossible.
The bluetooth in the iPhone is Class-2, with a 10-meter range, approximately.
Unfortunately I can't answer the other parts of your question.
One device can be connected up to 8 others. It all depends on the iPhone bluetooth API (which I don't know anything about), but with Bluetooth itself you could then send data to multiple devices.
I tether my iPhone to my laptop over bluetooth every day, and I seem to remember having done that at the same time as using a bluetooth headset. YMMV.
It’s the latest incarnation of Bluetooth, the wireless device-to-device technology that allows your phone to talk to headsets, car stereos, keyboards and other devices directly, without the need for a router or shared wireless network.

iPhone to iPhone communication

I'm kind of curious how I should approach a problem with iPhones and communication between two phones.
I have an idea for an application that needs to send data between two known phones. The problem is that the data could be very small or very large. I want to have intermediate storage on a server and a messaging layer, but I want there to be performant means to communicate between devices for shorter, unimportant messages.
You always hear about networking and client to client communication with popular platforms and protocols, but I'm curious what people's thoughts are on doing p2p style communication with an iPhone.
I'm pretty sure it should (and can) be treated as just a simple addressable machine... so I would have to build NAT traversing network code into the iPhone itself. A thought I had would be some sort of UPnP situation where I would ask to NAT a particular port for communication to the devices... but I guess I could just as easily turn it into a polling situation.
Granted, I understand that Apple will have a "push" mechanism for developers eventually but I want to get the app out the door before hand...
Just curious about thoughts on this type of thing... any thoughts on multi-player game situations would also directly apply to (and benefit from) this question.
Have you given the WiTap sample from Apple a try? It addresses the issue of discoverability (via Bonjour) and connectivity (via basic TCP). It may not be as robust as what you are looking for, but it's worth a look:
http://developer.apple.com/iphone/library/samplecode/WiTap/index.html
Look at the docs for Game Kit in the iPhone 3.0 SDK. It allows iPhones to connect to one another locally with Bluetooth, or via wi-fi/3G. It addresses both peer-to-peer and client-server architectures. It provides unreliable and reliable links.