Example of Bluetooth/Bonjour communication on iOS5 - iphone

Up until iOS5 CFNetwork was all you had to use to be able to find and connect to devices using both WiFi and Bluetooth, but as of iOS5 Apple decided to restrict CFNetowrk to only find and comunicate with services over WiFi (Technical Q&A QA1753) So I was left with a huge amount of code that I cant use no more and must now focus on C based implementation using C based API to rewrite bluetooth communication over bonjour.
Since this is the low level type of code, and I am not a deep C diver, I would like to know if there are examples or even better sample code of such communication, where you have a Server class and Browser class. It will take me ages to write it my self, so if you know any of those samples I would greatly appreciate it.

You should check out to see if Apple GameKit would fit your needs.
GameKit handles pairing Bluetooth devices. You implement you own pairing of WiFi connected devices. GameKit handles the rest of the communication.
I was facing similar problems wanting to use both WiFi and Bluetooth. GameKit worked very well for me. Reduced my networking code by more than half.
Apple has good sample code on their developer site.

Related

How to get surrounding networks with strength in iOS?

Is there any frameworks for find out the surrounding networks and network strength. Please tell me if it is possible or not in ios 4/5/6. Either is there any sample code for this.
For example i am using in iPhone Airtel network. Based on Airtel network i need to find what are other networks in that particular area and what is the signal strength of that network.
Thanks in advance.
As far as i know this cant be done using public API's. You need to use private API's check thi s out MobileApple80211 framework.
Yes it is possible. In fact there is an awesome 3rd Party library for this called iPhone-Wireless
This provides you -
view the wireless networks in your area.
signal strength of each network.
For iOS 5 you'll need a jailbroken iPhone. Guvener Gokce has a very educational blog post on this: iPhone Wireless Scanner iOS5
Hope this helps but keep in mind that this library uses private API's and your app might get rejected from app store.
UPDATE: Check this out too - Accessing iPhone WiFi Information via SDK

setting up iPhone P2P only over bluetooth and without GKPeerPickerController

I want to use a custom interface to connect with other iDevices in a p2p game. I know I can either use GKSession and GKSessionDelegate or use the lower level Bonjour browsing. But both of them will search for devices both over bluetooth AND wifi.
I want to list only bluetooth devices. I know this was answered in the past as impossible, but the Flight Control app seems to be able to do it.
I thought I would answer to let you know that YOU ARE NOT ALONE, I am trying to do the same thing and it is kicking my butt! This link might help you:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/40710-gamekit-api.html
I am trying to setup a server/client relationship and that requires me to use my own custom interface too.

Multiple peers connected

I'm developing a game that requires up to four iPhones or iPod Touch to connect each other to play in turns.
My question is, how can I accomplish this via GameKit. I've read that using client/server sessions is the way of doing it. But I can't find any examples that would illustrate this.
Is it really possible to do it, or there can only be two devices connected at a time.
I'd really appreciate if you all could help me with a code sample.
Thanks.
What you are trying to do is possible with the Gamekit framework. Easiest method is to use bluetooth, which means short range (as in the same room). I'm working on a similar application with the Gamekit framework. Look at the sample code on developer.apple.com for GKTank and GKRocket. These game demos are for two devices, but the framework will support what you need. In a bluetooth piconet you can have eight devices connected. Hope this helps you get started.

Is it possible, in principle, for an Android device to interface with an iPhone over Bluetooth/GameKit?

(I am not interested in pure theory, but as a practical near or mid-term possibility, say within 12-24 months.)
As a developer familiar with (but not specializing in) two major smartphone platforms, should I expect an Android library to come out which can spoof itself onto an iPhone app's GameKit-based network. It seems reasonable that a Bluetooth interface between platforms might square the opportunity to make useful applications, in the same way that modems benefited PC/Mac platforms via Metcalfe's Law.
I am looking for one of two answers:
Is this obviously not likely (e.g. because of encryption)? If so, what is the reason? Is it possible in principle, but requiring years of reverse-engineering (like SMB/CIFS/Samba)? Or is it a no-brainer and just a matter of time? Please give evidence supporting your reason.
Is there an alternative way to have direct peer-to-peer networking besides GameKit? For example, a hand-rolled network using Bluetooth or ad-hoc WiFi? It would be nice to spoof an Android device into an existing iPhone app but my main question is, can the devices speak with each other at all!
Yes, it is possible. GameKit is a protocol using TCP and/or UDP over a BNEP Bluetooth connection. It also uses a trick to identify other iOS devices using the Extended Inquiry mechanism in Bluetooth 2.1+.
I was able to simulate the EIR responses, now, someone needs to reverse engineer the GameKit protocol. This doesn't need Bluetooth, as it is also used for GameKit connections over WLAN.
If anybody can re-implment GameKit for WLAN connections, I can finish the Bluetooth version.
No, and it wont come soon or even at all... Apple pride themselves with their security features, and bluetooth connections can access private data. There will probably not be any cross platform bluetooth framework until something is agreed upon by both companies.
Bump as said by a previous answerer uses a remote server, and the data transferred is not via BT.
GameKit is Bonjour so a Bonjour (which is on IP) over Bluetooth on Android should work.
That should be possible as Bluetooth is capable of setting up tcp/ip networks. Though I have no knowledge of the IPhone SDK whatsoever, but Android does have a BluetoothSocket and BluetoothServerSocket for TCP connections.
This article, http://blog.moritzhaarmann.de/blog/2014/04/27/sorry-state-of-p2p/ written in 2014, suggest it is possible via Bluetooth LE. Available in Android 4.3+ and iOS6+
Two issues:
According to the Android Dashboard only around 30 percent of Android devices support Bluetooth LE https://developer.android.com/about/dashboards/index.html?utm_source=ausdroid.net
Communication between Android-to-Android must be done using some other method (which is not a big problem) because Android devices cannot act as server for B LE connections.
Bounjour on the iPhone gives you full access to all of the Bluetooth protocols, so you don't have to use GameKit. As for when someone will provide an easy to use iPhone to Android GameKit like framework - hard to tell.
An iPhone can already talk to any other Bluetooth device using Bonjour today.
-t
It is absolutely possible! In fact I am amazed that more people haven't done it!
Theory:
Bluetooth is just a wireless socket that you push data across and it comes across the other side, just like tcp/ip.
Practice:
http://www.techcrunch.com/2009/11/11/bump-goes-cross-platform-with-new-android-app-upgrades-iphone-version-too/
Better yet, Bump is cross-platform, which means that you can bump an Android phone with an iPhone and it should work seamlessly.

iPhone Gamekit peer with a desktop peer

I am looking for a way to establish a wireless connection between an iPhone and a desktop client. Gamekit looks promising but all the examples / documentation only explain iPhone to iPhone.
Are there examples / documentation for an Gamekit peer on the desktop (cocoa or java)?
What are the alternatives without doing to much low level socket programming?
The iPhone emulator does not run these bluetooth p2p connections. Hence, it can only be tested with real hardware.
It is a little confusing because the GKSession reference talks only about being a way to connect peers over bluetooth, while the GKPeerPickerController states "can be configured to select between Bluetooth and Internet connections." However there's a clear note there that they're not really going to help you with internet based connections.
This is unfortunately a non-answer, but...
GameKit is an abstraction of the bluetooth and wifi networking layers, allowing a specific set of protocols for communication between two devices -- to communicate with a desktop client, you would need to replicate all of the GameKit functionality on the desktop, since there is no comparable API on the desktop. This would not be a simple undertaking.
I would highly suggest developing something over bonjour, as #Jordan suggested. Bill Dudney's project (blog article). It's a great place to start.
Citing Game Kit Framework Reference's Features paragraph:
Peer-to-peer connectivity allows your game to create an ad hoc Bluetooth or wireless network between multiple iPhones in the same local area. Although designed with games in mind, this network is useful for any type of data exchange among users of your app. For example, an app could use peer-to-peer connectivity to share electronic business cards or other data. This functionality is only available on iOS. You can also get the same functionality using Game Center.