I trying to get the Status of iPhone/iPod Bluetooth that whether it is ON or OFF programmatically. Is it possible using some Apple API or third party API.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
To disable the default alert message you just need to pass through an option dictionary when you instantiate the CBPeripheralManager:
SWIFT tested on iOS8+
Obviously you also need to implement the CKManagerDelegate delegate method peripheralManagerDidUpdateState as outlined above as well:
This solution is bit old , before apple introducing core bluetooth
Some updates on BadPirate's answer, with iOS7 you can set the central manager not to show the alert when allocating the manager object by giving it a NSDictionary that has key "CBCentralManagerOptionShowPowerAlertKey" set to 0.
There is a way on iOS 5 and above using CoreBluetooth. The class you can use is CBCentralManager. It has a property 'state' that you can check to see if Bluetooth is on or not. (the enum CBCentralManagerState has the value(s) you want to check against).
A little bit of research into Sam's answer that I thought I'd share You can do so without utilizing private API, but with a few caveats:
Simply allocating the class will cause your application to ask permission to use the bluetooth stack from the user (may not be desired), and if they refuse, the only thing you'll see is CBCentralManagerStateUnauthorizediOS7+ Revision: Aforementioned strike-through can now be prevented, see comments below which point to this answer which explains you can set CoreBluetooth'sCBCentralManagerOptionShowPowerAlertKey
option to NO to prevent permissions prompt.That being said, this method does seem to provide real time updates of bluetooth stack state.
After including the CoreBluetooth framework,
These tests were easy to perform using:
This answer has been updated from the original Objective-C to Swift 4.0.
It is assumed that you have already created a bluetooth manager and assigned the delegate to the
ViewController
class.