During development I got a problem witch related to the connection central and peripheral. When one of the central already connected with perepheral I have to don't allow to connect other central. Maybe someone nows how can I check does the peripheral already connected?
Core Bluetooth. How can I check does peripheral already connect?
1.9k views Asked by Uladzislau Simanau At
2
There are 2 answers
0
dennis_ka
On
If you simply want to know whether a peripheral is connected to a central, then you can simply check its state. You can do this immediately during discovery.
public func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
guard peripheral.state == .disconnected else { return }
// Peripheral is not connected to any central.
}
Related Questions in SWIFT
- Overlapping UICollectionView in storyboard
- Cannot pod spec lint because of undeclared type errors
- Swift code with multiple NSDateFormatter - optimization
- How do I add multiple in app purchases in Swift Spritekit?
- cellForRowAtIndexPath and prepareForSegue return different label colors
- Getting this message in my console in xcode "Ignoring restoreCompletedTransactionsWithApplicationUsername: because already restoring transactions"?
- Change background of an Accessory View in a UITableViewCell
- fade in an bounce animation subview
- Create a PFObject and PFRelation after PFUser Sign Up
- Swift 2 - Pattern matching in "if"
Related Questions in UIKIT
- How to change position of UIButton?
- Adding a subview to a view controller messes up with a table view
- Change the View BackgroundColor on Tap
- iOS GameOver screen does not appear
- Change the parent of a view
- How do I toggle hidden of a label while a button is pressed?
- Change the owner account id of a file in iOS
- Importing document with UIDocumentPickerViewController warns "fileprovider plugin was invalidated"
- Displaying a stock iOS notification banner when your app is open and in the foreground?
- Observe the transition state of UIPageViewController
Related Questions in CORE-BLUETOOTH
- MFi Program by Apple
- How to use core bluetooth framework to connect Headsets/handsfree?
- Is it possible to create an app that when installed the user can easily turn Bluetooth/NFC ON and OFF by double clicking the Home button?
- Swift, CoreBluetooth: services and characteristics
- How to detect with CoreBluetooth when a peripheral disappears?
- How to reset CBPeripheralManager of CoreBluetooth in Swift?
- How to detect if a non-connected peripheral leaves range in Swift?
- can we stream audio using corebluetooth technology to multiple ios devices?
- Simulating HID on OSX : IOBluetooth or CoreBluetooth?
- Read from an external bluetooth keyboard without UITextField
Related Questions in PERIPHERALS
- Is it possible to interact with an arbitrary client peripheral from a webapp?
- Atomic access to ARM peripheral registers
- Memory mapped ADC on DE1-SoC using HPS (hard-core processor)
- How are memory mapped devices allocated an address and how does the CPU know what it is
- Is consume a client web service from web browser good practice?
- How to programmatically wake an external screen attached to an iPad
- Android 5.0 peripheral mode, how to add data to a scan response
- SPI test case in C for Pulpissimo
- Core Bluetooth. How can I check does peripheral already connect?
- Why are periperal registers 16 bit only on 32 bit MCUs such as STM32 and GD32VF103?
Related Questions in CENTRAL
- Filebeat Central Management Alternative
- How do i uninstall ODK Central?
- Core Bluetooth. How can I check does peripheral already connect?
- Sybase Python SQL Anywhere 17 SQL Central
- Registering call logging service into RingCentral Embeddable results in undefined error
- Express central error handling with app.use
- SharePoint 2016 Custom Timer Job Not Showing in Job Definition
- How do I authenticate with biometrics on every activity centrally
- How can users run a python script without installing python on their local machines and without converting the script into an executable?
- What is official search engine for Maven Central?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Call
retrieveConnectedPeripherals(withServices:)to get a list of currently-connected peripherals for a given list of service UUIDs. These are connected to the phone, not to your app. You still need to callconnectto connect them the currently running app (exactly like you would if you discovered them). This call is synchronous, since the OS already knows all the connected devices and can just return them.Typically this list is empty. The most common production reason for it to be non-empty is that another app has connected to the device (LightBlue or some other Bluetooth scanner for example). During development, however, it is very common that the app gets killed, and in that case the phone may not have dropped the connection yet when you relaunch the app, and this will handle that situation.
While you can scan for all devices by passing
niltoscanForPeripherals, there is no equivalent way to retrieve "all connected devices" You must list the desired service UUIDs. I don't believe this should be a problem in your case.