How can I create a Bluetooth application for the iPhone? What do I need to know about controllers? Delegate methods?
The GameKit framework contains APIs to allow communications over a Bluetooth network. Using these APIs, you can create peer-to-peer games and applications with ease.All the various APIs for accessing the Bluetooth is located in the GameKit framework.
Here is good example code in this... link
Hope it helps you.
Related
This might seem like a dumb question, but can GameKit be used for apps other than games? That is, will Apple approve an app that uses GameKit for bluetooth purposes but doesn't use them for games? Or will they reject it based on "misuse of hardware/software" or whatever that rule is?
From Apple's "Game Kit Programming Guide":
Peer-to-peer connectivity allows your game to create an ad-hoc Bluetooth or local wireless network between multiple iOS-based devices. Although designed with games in mind, this network is useful for any type of data exchange among users of your application. For example, an application could use peer-to-peer connectivity to share electronic business cards or other data.
This clearly answers your question.
Yes, GameKit can be used for things other than games, in fact, in some situations it is better than using other communication frameworks, as it is ridiculously simply to create a local network connection between two devices, and you can send any data you wish over the connection you create.
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.
which one is better for implementing chat for the iPhone with users in the current area
gameKit or bounjour ?
Bonjour is simply service discovery over the network, it has nothing to do with actually transferring data.
Gamekit makes use of Bonjour under the hood to discover other clients, and then provides extra APIs ob top of bonjour to transfer data between clients.
Game Kit. Because it builds on top of Bonjour to find those other players and then provides an API to communicate with them. Check out the documentation.
Using GameKit limits you to iOS/Mac devices. Bonjour is open source and available for Android and Windows.
My vote is on GameKit. Not only does it allow you to send arbitrary data, but you can set up a voice chat with about two API calls.
var chat:VoiceChat = match.getVoiceChat("all");
// join the voice chat so the player can hear other players
chat.join();
// set talk to true so other players can hear this player
chat.talk = true;
Note: The above is using a Native Extension for as3, but it's basically the same API on iOS.
GameKit is fine for games, but keep it in your mind that Apple may not allow you to use GameKit features for non-game apps.
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.
i'm participating in the iPhone Developer Program and i have access to the iPhone 3.0 firmware and SDK.
one of the new features of the iPhone 3.0 -- is ability to use Bluetooth, but i can't find any documentation about it.
can someone point me please -- where is it?
The only way of using bluetooth directly is if you join the Made for iPod / Works With iPhone program and integrate the Apple authentication chip into your custom device. Once you've done that, you can use the ExternalAccessory framework which exposes a low-level IO stream API to the device.
Frameworks like Core Audio will let you play and record music via bluetooth headsets and the Gamekit framework will let you discover and talk to other devices via bluetooth, but the fact that it's bluetooth is not exposed to the developer at all.
Look at the GameKit API - it provides simple high level access to BlueTooth connections between devices (built on Apple's Bonjour discovery service).
If I recall correctly, you aren't allowed direct access to the Bluetooth, but rather, you are able to use certain API calls that will search for nearby devices. However, I'm not a developer currently, so I can't point you at any documentation. Perhaps someone else can back me up with a bit more information.
My iphone 3G & 4 will connect to my Sony BT1500 car head unit which was made well before iPhone existed (i.e it's not iPod signed).