Pablosproject
Pablosproject

Reputation: 1424

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

Upvotes: 3

Views: 1606

Answers (1)

Atomix
Atomix

Reputation: 13842

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.

Upvotes: 5

Related Questions