@Claude31 just last question can we get iPhone bluetooth unique id programatically?
I'm also working on thing this..
Post
Replies
Boosts
Views
Activity
@Claude31
Thanks for your help now I'm able to search the app in background state but now problem is that.
I want search the bluetooth devices when app is Inactive state.
We can do this by using the 'willRestoreState' function but don't know how to implement that.
And didn't get any proper document on this.
So please can you help me on this.
@Lebets_VI
Did you find any solution on this.
And do you know when app is in background or inactive can we just search the near by bluetooth devices.
Thanks for your Ans.
when inactive, you can search only for devices already found, using the UUID
>> Actually I'm not connecting any device just searching the device and find the distance.
So, can we do that without connecting the device can we just search the device.
2. when inactive, you cannot discover new devices
>> Completely Agree with you, Do you have any document from apple, where they mention this.
I check this link :link - https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#//apple_ref/doc/uid/TP40013257-CH7-SW5
They mention here we can do this by using the some Restore delegate method, but I'm not able to do that.
And not able to find where they mention we can only do this if we already connected to that devices in past.
And finally, I just want to know that, Can we search the BLE / Bluetooth devices when app is inactive mode.
Thanks for your the Answer,
I tried this link but not working.
https://stackoverflow.com/questions/57904096/how-to-scan-ble-devices-in-background
Do you know some steps to achieve this, so I can follow and make it working.
Please correct me If I'm wrong,
Its possible to just search the new devices when app inactive mode..
@Claude31,
Hey thanks for your response, Actually I have the same question related to this.
Can we search the BLE devices when my app in background mode.
Can we search the BLE devices when our app is Inactive mode,
I searched lot regarding this but not get a proper solutions on this.
@Claude Thanks for your answer. I'm done with distance but now the distance which I get is not current.
For Android they use the Kalman filter to remove the noise and get accuracy so similar to that how can i use the Kalman filter in iOS (swift).
Thanksss
Thanks for your Ans I'm able to find the bluetooth device now, but problem is now getting only one device in the list.
there are 4 device around but I can saw only one.
currently i'm using this to find the bluetooth devices
let options: [String: Any] = [CBCentralManagerScanOptionAllowDuplicatesKey:NSNumber(value: false)]
centralManager?.scanForPeripherals(withServices: nil, options: options)-
@Claude31 Please check the code in comment.
import UIKit
import CoreBluetooth
class ViewController: UIViewController {
@IBOutlet weak var tblOfList: UITableView!
@IBOutlet weak var btnOfScan: UIButton!
var peripherals:[CBPeripheral] = []
var centralManager: CBCentralManager!
override func viewDidLoad() {
super.viewDidLoad()
self.tblOfList.tableFooterView = UIView()
centralManager = CBCentralManager(delegate: self, queue: .main)
}
@IBAction func btnScanClick( sender: Any) {
print("scan Start")
//let options: [String: Any] = [CBCentralManagerScanOptionAllowDuplicatesKey:NSNumber(value: false)]
centralManager?.scanForPeripherals(withServices: nil, options: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 60.0) {
self.centralManager.stopScan()
print("Scanning stop")
}
}
}
extension ViewController : UITableViewDelegate,UITableViewDataSource {
func tableView( tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return peripherals.count
}
func tableView( tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tblOfList.dequeueReusableCell(withIdentifier: "listCell", for: indexPath) as! listCell
let peripheral = peripherals[indexPath.row]
cell.lblOfDeviceName?.text = peripheral.name
return cell
}
func tableView( tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let peripheral = peripherals[indexPath.row]
print("Details : ", peripheral)
}
}
extension ViewController : CBPeripheralDelegate, CBCentralManagerDelegate{
func centralManager( central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
self.peripherals.append(peripheral)
print("Discovered \(peripheral.name ?? "")")
self.tblOfList.reloadData()
}
func centralManagerDidUpdateState( central: CBCentralManager) {
switch central.state {
case .unknown:
print("central.state is .unknown")
case .resetting:
print("central.state is .resetting")
case .unsupported:
print("central.state is .unsupported")
case .unauthorized:
print("central.state is .unauthorized")
case .poweredOff:
print("central.state is .poweredOff")
case .poweredOn:
print("central.state is .poweredOn")
@unknown default:
fatalError()
}
}
func centralManager( central: CBCentralManager, didConnect peripheral: CBPeripheral) {
print("Connected to "+peripheral.name!)
}
func centralManager( central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {
print(error!)
}
}