Using the new MonoTouch.CoreBluetooth namespace - ios5

I have found a few samples on how to use GameKit for bluetooth communication and even accessing bluetooth functionality using native code but no example on how to use the MonoTouch.CoreBluetooth namespace.
Seems a shame using hacks when the full implementation is just waiting to be used.
Can anyone please share a sample or source (a link to a book would work as well) for the new MonoTouch.CoreBluetooth.

CoreBluetooth is just for communicating with devices that utilise the Bluetooth Low Energy Profile, such as watches, heart rate monitors etc.. It is not possible to use any other profiles with CoreBluetooth, so not possible to connect to another phone, a computer etc...
(Although given the name, I hope in future apple will provide lower level access to bluetooth comms in this framework)

Related

Peer-to-peer communication between iOS devices

I am trying to prototype a solution to a problem and am currently exploring multiple routes I could try. Is it possible for one iOS device, running a certain app, to communicate directly with another iOS device, running the same application - without the need to be on the same LAN?
Solutions I am currently investigating are using Bluetooth and ad-hoc wireless connections.
Ideally, the application when installed would ask the user for the required permissions, and then would accept and/or send data to/from another client after a handshake had happened.
My concern with Bluetooth is that 'pairing' would need to happen with every device, rather than happen in the background once the user has installed the app. I have a feeling what I am talking about isn't possible from what I've been reading elsewhere on Stackoverflow.
Take a look at Bluetooth Low Energy.
https://developer.apple.com/library/ios/#samplecode/BTLE_Transfer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40012927
Here is another example,
https://github.com/KhaosT/CBPeripheralManager-Demo
You might also want to look into GameKit and peer-to-peer connectivity there.
I can't tell you anything about it, but you might try looking at iOS 7. If that's an option, I'd take a look. Can't talk about what it is because of NDA though.
Depending on what you need to communicate, you could try checking out this project, which lets you share arrays of strings between iOS devices over Bluetooth LE.
You don't need to "pair" the devices and it can still communicate while the app is in the background. SimpleShare
Hope it helps!
From the documentation of MultipeerGroupChat:
MultipeerGroupChat sample application utilizes the Multipeer Connectivity framework to enable nearby users to discover, connected, and send data between each other. This sample simulates a simple chat interface where up to 8 devices can connect with each other and send text messages or images to each other. Here you will learn how to bring up framework UI for discovery and connections and also how to monitor session state, listen for incoming data and resources, and send data and resources.
This is an excellent example at developer.apple.com here is the link
https://developer.apple.com/library/ios/samplecode/MultipeerGroupChat/Introduction/Intro.html
Also this tutorial from Ralf Ebert demonstrates how to use Multipeer Connectivity framework for peer communication should help you.
https://www.ralfebert.de/tutorials/ios-swift-multipeer-connectivity/

What profile can I use with CoreBluetooth?

I looking for informations about CoreBluetooth, I see iPhone4s/5 support Bluetooth 4.0 and Bluetooth LE.
Also, according to this note, I can use these profiles :
Hands-Free Profile (HFP 1.6)
Phone Book Access Profile (PBAP)
Advanced Audio Distribution Profile (A2DP)
Audio/Video Remote Control Profile (AVRCP 1.4)
Personal Area Network Profile (PAN)
Human Interface Device Profile (HID)
Message Access Profile (MAP)
Can I have access to them using CoreBluetooth and, if so, how could I access to them ?
You can't use any of the mentioned profiles if you want to communicate from the application. Core Bluetooth is meant for low energy,You can only implement GATT Profiles(like Heart Rate,Alert Notification) with BLE and BLE is for small data rates.You can only write or read characteristics to/from the device. In order to implement any of the mentioned profiles you require Serial Port Profile, which is supported only through MFi using External Accessory Framework.
GATT Profiles
http://developer.bluetooth.org/gatt/profiles/Pages/ProfilesHome.aspx
You can find External Accessory Framework documentation in the link below.
http://developer.apple.com/library/ios/#documentation/ExternalAccessory/Reference/ExternalAccessoryFrameworkReference/_index.html
MFi
https://developer.apple.com/programs/mfi/
CoreBluetooth framework is for Bluetooth Low Energy. The note seems to be dealing with "classic" Bluetooth only (since you see "old" devices) . In that case, you'll have to use ExternalAccessory framework. Its two technologies quite different, as you could see by searching in Google or in different questions here in StackOverflow.
There is a sample from Apple dealing with ExternalAccessory framework : EADemo.

Bluetooth LE Profile for reading measured data

I read a lot about Bluetooth LE in the past hours, but I do not really understand how profiles work. I want to pair an iPhone with a self-made device over BTLE.
The device should send measured temperature values, humidity or other values over Bluetooth and the iPhone should read that data.
I read about different profiles in the BTLE specs (even about heart measurement), but how does one proceed, when reading CO-emission for example?
Thanks a lot!
Regards, mary
There are two sides to this: the profile you'll define on your device and the code you'll write to communicate with this profile in your iOS application.
On the device, you'll define a profile with specific services for the measurements you want to gather. There are several standard Bluetooth LE profiles which you can find in a list on the main Bluetooth developer site. These include profiles for temperature, heart rate, and walking cadence, among others, so if you are providing measurements in one of these categories you can make your device provide one of those services and it will be usable with any iOS application that reads from that service.
For values that aren't covered by one of the existing services, such as the humidity readings you mention, you'll need to create your own custom service. You'll just have to define the service characteristics (what type of data you'll provide and how you'll provide it) and give this service a unique identifier, because it's one you're creating and not part of the standard ones laid out by the Bluetooth organization.
How you define these services and characteristics will depend on the specific Bluetooth LE hardware you use for your device. I've done most of my work recently on Bluegiga's BLE112 chip, which combines a low-power microcontroller with a Bluetooth LE transmitter. They have very good tools for defining device profiles and creating matching firmware, and it's reasonably straightforward to set this up on their chips. I can't speak for other manufacturers, but they most likely have something similar.
Once you have a profile defined on your hardware, you'll need to look for devices advertising it and be able to connect to them within your iOS application. You'll use Core Bluetooth for this, and I highly recommend starting with one of Apple's sample applications, such as their Temperature Sensor example. That example uses the standard health thermometer profile, but you can tweak it to find your proprietary services in addition to the temperature readings. You can see how they read and process the binary data returned from the LE device in that example.
I highly recommend watching Apple's two WWDC 2012 session videos on the topic, Session 703 - Core Bluetooth 101 and Session 705 - Advanced Core Bluetooth, because they provide a lot of background on the topic and show practical examples of this in use.

Communication between two iOS devices

I am looking for a way to have one iPhone app send a message to another app on a different phone (sort of like a Sender-Receiver set up). I am looking for the best possible way to do this. Does anyone have any ideas and/or tutorials?
Thanks for the help.
You should use GameKit. It is super easy to send messages between two iOS devices using it. Here's a great tutorial: Game Kit. You can also get more information about it here from the docs: About Game Kit.
You communicate by creating an ad-hoc bluetooth or local wireless network.
lmirak provided insightful info about device communication(especially about GameKit). I would like to add one more solution. You can use WiFi network to do your device communication.
See the link or download the sample application from developer.apple
The sample application named as WiTap. It demonstrates how to achieve network communication between applications. Using Bonjour, the application both advertises itself on the local network and displays a list of other instances of this application on the network.
If your app is only going to run on iOS, then you should use the fantastic MultipeerConnectivity library. https://developer.apple.com/documentation/multipeerconnectivity
If you need a solution that will work cross-platform, then one way to accomplish this is using sockets and connecting over a local network. On iOS you can use CocoaAsyncPods for sockets and NetService for discovery.
Here is a basic example app that does this: https://github.com/brendaninnis/LocalNetworkingApp
, which I explain in great detail here: http://brendaninnis.ca/connect-nearby-devices-part-1.html

Example of Bluetooth/Bonjour communication on iOS5

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.