I'm trying some iOS test applications on the new Mac mini, that supports Bluetooth Low Energy. The CoreBluetooth framework is used in those. However, I'm not able to get Bluetooth working in the iPhone simulator, that is part of Xcode.
When I allocate a new CBCentralManager, centralManagerDidUpdateState: receives CBCentralManagerStatePoweredOff which stands for Bluetooth is currently powered off.
The first time I ran the text application, a box was then opened up that looked pretty bugged (only language variables were used, not the actual texts) and with two buttons. The first led me to the settings panel where there was an option to enable Bluetooth. However, after I told it to enable Bluetooth, it just shows the spinning animation, and it won't either complete or cancel. Even after rebooting the Mac, there is still only the spinning animation. The box also does not open up anymore.
Essentially, I think that the iPhone simulator should support Bluetooth Low Energy. Otherwise, it does not really make sense that there is an option in the settings application on the simulator. Also, the central manager state is CBCentralManagerStatePoweredOff but not CBCentralManagerStateUnsupported which would stand for The platform doesn't support Bluetooth Low Energy. This gives also hope that support could exist.
Does the iPhone simulator support Bluetooth Low Energy?
If yes, how can I enable it?
The simulator does support Bluetooth Low Energy (4.0) according to this appnote from Apple. The only problem is that even if you have a computer with BLE inside, you will not be able to use the simulator together with it, because (I think) you occupy the availability on BLE for other devices to discover your computer, thereby restricting the functionality of the Mac.
So if you go get yourself a BLE USB dongle you will be able to use it in simulator.
EDIT: Adding information from #JoeShaw:
Unfortunately it appears as though Core Bluetooth support has been dropped from the simulator for iOS 7. Reference: doubleencore.com/2013/09/whats-new-in-bluetooth-le-ios-7. In addition, the linked technote seems to have been removed.
I have been using the simulator to test BLE apps - but you need to be on OSX 10.7. As Wilhelmsen mentioned, you also need a BLE USB dongle. In addition, you need to set an NVRAM setting:
$sudo nvram bluetoothHostControllerSwitchBehavior="never"
See this Technical Note from Apple for more details on using the simulator to test BLE apps: http://developer.apple.com/library/ios/#technotes/tn2295/_index.html
According to http://www.doubleencore.com/2013/09/whats-new-in-bluetooth-le-ios-7/, Core Bluetooth support has been dropped from the simulator as of iOS 7. I haven't figured out why yet, but it means you will need to test on real hardware in the future.
It also appears as though Apple has removed Tech Note 2295, as I get redirected when I hit the URL.
I've found that Apple writes in their own samples that the simulator cannot be used to test Core Bluetooth-based applications.
Important:
This project requires a Bluetooth LE Capable Device (Currently only the iPhone 4S) and will not work on the simulator.
I've been working on a BLE app for the past week and can say with confidence that no, the simulator does not support BLE unless the mac that your using has BLE(Macbook Air) - but even then i'm not 100% sure how to enable this(most likely by just turing on BLE on your mac and on the simulator).
If you don't have a BLE enabled mac, have to find yourself a 4s to do testing with!
One alternative approach to using CoreBluetooth in the Simulator is to use Nordic Semiconductor's CoreBluetooth-Mock library, which allows you to stub-out CoreBluetooth and provide simulated/mock peripherals for use when working with the simulator:
https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock
It does require some minor code changes, but the interface it provides is almost identical to that of CoreBluetooth.
It's also great for writing integration tests too.
Actually I tried in the simulator and does not work.
The simulator does not recognize if you have a Bluetooth 4.0 in your computer but if you are using Command line tool projects in Xcode then it works. just for the cases you want to create something in Command line tool.
Related
I'm trying some iOS test applications on the new Mac mini, that supports Bluetooth Low Energy. The CoreBluetooth framework is used in those. However, I'm not able to get Bluetooth working in the iPhone simulator, that is part of Xcode.
When I allocate a new CBCentralManager, centralManagerDidUpdateState: receives CBCentralManagerStatePoweredOff which stands for Bluetooth is currently powered off.
The first time I ran the text application, a box was then opened up that looked pretty bugged (only language variables were used, not the actual texts) and with two buttons. The first led me to the settings panel where there was an option to enable Bluetooth. However, after I told it to enable Bluetooth, it just shows the spinning animation, and it won't either complete or cancel. Even after rebooting the Mac, there is still only the spinning animation. The box also does not open up anymore.
Essentially, I think that the iPhone simulator should support Bluetooth Low Energy. Otherwise, it does not really make sense that there is an option in the settings application on the simulator. Also, the central manager state is CBCentralManagerStatePoweredOff but not CBCentralManagerStateUnsupported which would stand for The platform doesn't support Bluetooth Low Energy. This gives also hope that support could exist.
Does the iPhone simulator support Bluetooth Low Energy?
If yes, how can I enable it?
The simulator does support Bluetooth Low Energy (4.0) according to this appnote from Apple. The only problem is that even if you have a computer with BLE inside, you will not be able to use the simulator together with it, because (I think) you occupy the availability on BLE for other devices to discover your computer, thereby restricting the functionality of the Mac.
So if you go get yourself a BLE USB dongle you will be able to use it in simulator.
EDIT: Adding information from #JoeShaw:
Unfortunately it appears as though Core Bluetooth support has been dropped from the simulator for iOS 7. Reference: doubleencore.com/2013/09/whats-new-in-bluetooth-le-ios-7. In addition, the linked technote seems to have been removed.
I have been using the simulator to test BLE apps - but you need to be on OSX 10.7. As Wilhelmsen mentioned, you also need a BLE USB dongle. In addition, you need to set an NVRAM setting:
$sudo nvram bluetoothHostControllerSwitchBehavior="never"
See this Technical Note from Apple for more details on using the simulator to test BLE apps: http://developer.apple.com/library/ios/#technotes/tn2295/_index.html
According to http://www.doubleencore.com/2013/09/whats-new-in-bluetooth-le-ios-7/, Core Bluetooth support has been dropped from the simulator as of iOS 7. I haven't figured out why yet, but it means you will need to test on real hardware in the future.
It also appears as though Apple has removed Tech Note 2295, as I get redirected when I hit the URL.
I've found that Apple writes in their own samples that the simulator cannot be used to test Core Bluetooth-based applications.
Important:
This project requires a Bluetooth LE Capable Device (Currently only the iPhone 4S) and will not work on the simulator.
I've been working on a BLE app for the past week and can say with confidence that no, the simulator does not support BLE unless the mac that your using has BLE(Macbook Air) - but even then i'm not 100% sure how to enable this(most likely by just turing on BLE on your mac and on the simulator).
If you don't have a BLE enabled mac, have to find yourself a 4s to do testing with!
One alternative approach to using CoreBluetooth in the Simulator is to use Nordic Semiconductor's CoreBluetooth-Mock library, which allows you to stub-out CoreBluetooth and provide simulated/mock peripherals for use when working with the simulator:
https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock
It does require some minor code changes, but the interface it provides is almost identical to that of CoreBluetooth.
It's also great for writing integration tests too.
Actually I tried in the simulator and does not work.
The simulator does not recognize if you have a Bluetooth 4.0 in your computer but if you are using Command line tool projects in Xcode then it works. just for the cases you want to create something in Command line tool.
I have a request of implementing an iOS application which will be able to communicate with bluetooth device. The chip on that device has Bluetooth 3. The App will be privately distributed, so we don't need AppStore review and we can use anything - the only requirement is, no iPhone jailbreaking. The purpose of the application in reading diagnostic data from the device and sending a few commands to it - like turn left, turn right, setValue - nothing special (it is a special valve, which can be remotely controlled).
Now if a learned correctly the options with using Bluetooth on iOS are:
CoreBluetooth: library for Bluetooth 4.0 LE devices. It cannot be used, because Bluetooth chip is 3.0
ExternalAccessory: the device must be MFI certified, if this option is about to be used. Quite hard that hardware producer will go into the MFI certification, so at the moment not an options.
Bluetooth.framework: private framework which sounded like a good option (I have managed to make it run on iOS9 and iOS10) but the communication with devices on iOS10 does not work anymore. On iOS 9.3.5 on iPhone5 I made it work, but only iOS9 is not an option
BTStack: available via Cydia, but this packages if I have learned correctly require iPhone jailbreaking. Sadly again not an option
The situation clearly does not look good here. I have also read rumors, that it might be possible to use HID bluetooth profile for communication (anyone tried that). is there any C Bluetooth library which could be run on iOS device and work with iOS10?
Thanks for any iadeas.
I see questions surrounding issues such as "Device Unsupported" in many posts on this website and on the internet, so I feel like the problems I am having are not unique.
What perplexes me (and trust me I have searched all day) is that I recently bought a new Macbook Pro computer (surely the BT on this thing is LE), upgraded to Mavericks, and am using Xcode 5. But no matter, what sample code I download, whether from the BT SIG or CSR, etc., I always get the same basic errors (on the iOS Simulator):
Something to the effect of "Device Unsupported" AND
Something about how it can't run because it's not powered on (and I did try to work around by wrapping the central.state call in an if block)
So, are the people like me who are starting to code Bluetooth today just screwed if we don't have LE devices? Did all of the BT code prior to 4.0 fall off the face of the earth or get deprecated?
Is there a simple way to force my code to run in some type of "non-LE" mode?
As for the code I'm using, I downloaded the Quick Start kit from the BT SIG, but nothing works, even simple scan programs that I have found. Ugh, any ideas out there?
My ultimate goal is to write something that will run without errors, load on my iPhone 4, and scan and pair with my car's stereo and grab all of the peripheral advertisements that it is sending out to see what all I can do with (to) the stereo.
Thanks all.
While your computer does have Bluetooth Low Energy/Bluetooth 4.0/Bluetooth Smart (they are all different names for the same thing) capabilities, these are not available to the simulator. A while ago you could add an additional BT4.0 dongle to the Mac and then access that from the simulator, but this is no longer supported - see Does the iPhone simulator in Xcode support Bluetooth Low Energy?
You can develop BT4.0/BLE code in Xcode for OSX with just your computer, but if you want to develop and test iOS code you will need a BLE capable iOS device (iPhone 4S or later, iPad mini/3rd gen/Air or an iPod Touch 5th generation)
Access to non BT4 devices is only via the Apple MFI program, with the exception of a few generic profiles, such as handsfree & A2DP streaming - but these are exposed to your program as audio devices, not as Bluetooth devices.
If you have an iPhone 4S (not iPhone 4) then you can use the LightBlue app from the App Store to see if your car stereo is advertising any BLE services (which it probably isn't).
crawdaddy18, Bluetooth Smart/4.0/LE are fundamentally different technologies then what we'll call Bluetooth Classic (2.0/2.1/EDR/BR...this is the stuff you are referring to with your car audio example). If you want to see what's going on with your car stereo, see what profiles it supports (should be listed in the documentation). Then take a look here:
https://developer.bluetooth.org/TechnologyOverview/Pages/Profiles.aspx#Profiles
This page lists all of the 'classic' profiles. You should find the ones that match your car on the list. You'll then know what functionality your car stereo supports.
Then, it's off to the races with OS documentation to look at the object models for classic Bluetooth. Usually these are either supported by an object model that represents the profile or are wrangled through RFCOM somehow...but each OS is a bit different.
But most of the tools that are out there, including the Application Accelerator, are geared to let you explore LE (Smart) devices out there. If you want to use something like the Application Accelerator to view non-LE devices, you'll have to re-jigger the code to switch the object models that you use in the OS' SDK. The reason that most recent tools you are finding now are geared towards the LE side of things is that that is where the massive growth in appcessories (and the Bluetooth industry) is heading. But there are TONS of sample code out there to help to create an app to scan and connect to classic Bluetooth devices as well.
I have a Bluetooth Low Energy (BLE) app that communicates with a BLE device through open connection. I am using CoreBluetooth library. After I upgraded my iPhone to iOS 7 and XCode to XCode 5. I recompiled my Bluetooth Low Energy app and found it no longer working. The connection is successful. The services and characteristics are discovered with no problems. Even the reading of the characteristics seems fine. But writing to a characteristic which should trigger some action on the BLE device has not any effect.
If I use XCode to download the same app to another iPhone with iOS 6, everything works fine. So I can determine the problem may be something with iOS 7 instead of XCode 5’s recompiling. It’s also possible XCode 5 prepares a different app for iOS 6 device even from a same project because I can see the app’s appearances are different on two devices.
So what’s changed from iOS 6 to iOS 7 that makes writing to characteristics failed?
I ran into the same problem, the issue is with the the firmware not your iOS Code. iOS6 was more relaxed with the characteristics types, but iOS7 is more stringent.
The WriteWithoutResponse flag for the Characteristic has to set explicitly to work with iOS7
I had used RedBear's Biscuit for Arduino at my startup to test our product, which worked wonderfully with iOS6 but when the app migrated to iOS7, the writes would fail quietly.
More detailed discussion is here (see update from Mattj949) # https://redbearlab.zendesk.com/entries/25031402-BLE-Mini-and-iOS-7
There are some Apple Threads on this issue, http://lists.apple.com/archives/bluetooth-dev/2013/Aug/msg00046.html and http://lists.apple.com/archives/bluetooth-dev/2013/Aug/msg00050.html
I'm trying to figure out why my BTLE TI CC2540 keyfob is working with my iPad 3 but not with the iOS Simulator equipped with a new GBU521 IOGEAR adapter on Mountain Lion.
I've been able to successfully connect the iOS 5 Simulator Bluetooth in the general settings (it says on, now) to my BT adapter, and to be considered as 'powered on' in my proof of concept app. I'm using a GBU521 IOGEAR adapter, which only worked after upgrading to Mountain Lion (tried Lion with some hack modifying some .kext files-- don't do that. Upgrading to Mountain Lion was impossible until I reverted that .kext). I then ran the Apple suggested nvram setting, rebooted, and it was able to recognize the BT adapter.
I'm able to communicate with my iPad 3 successfully (registering the button pushes, accelerometer, etc), but when I try to run it on the simulator, it just doesn't discover the device. It's telling me the BT state is CBCentralManagerStatePoweredOn, but then when I tell it to discover peripherals, it comes up with nothing.
How can I establish Bluetooth LE communication between the iOS Simulator and an LE-enabled iOS device?
(modified from my answer in other iOS Simulator Bluetooth thread here: Bluetooth Dongle and iOS Simulator)
Throw away the IOGEAR and pick up a Cirago BTA8000.
I'm not sure why you were able to turn Bluetooth on in the iOS Simulator (possibly related to your kext editing, which I tried too), but I suspect it's not actually on. I bought the IOGEAR you mention, in addition to the Cirago BTA8000, and the MediaLink 4.0 adapter. Turns out that anything based on the Broadcom chip won't work despite my MacBook having the exact same one built in, which means the MediaLink and IOGEAR don't work. My Cirago shipment just arrived this morning, and the Bluetooth slider in the iOS Simulator flicks to "ON" in less than a second.
If you want to experiment, I'd love to hear if other non-Broadcom chips work too.
Does your keyfob didn't came with a dongle? I'm planning to buy one :S
Update: I've just found this(But probably you have arleady seen this, it explains why you are using a separate adapter): http://developer.apple.com/library/ios/#technotes/tn2295/_index.html
Also the reviews on amazon of your adapter doesn't look very good. have you tried it with antoher device? http://www.amazon.com/IOGEAR-Bluetooth-Micro-Adapter-GBU521/dp/B007GFX0PY/ref=sr_1_1?ie=UTF8&qid=1344560021&sr=8-1&keywords=GBU521+IOGEAR