Reputation: 1965
I am using Core bluetooth framework and scanning few devices such as micromax A250,micromax A116 , samsung grand neo, HTC 610 and ipod 5s then i am not able to scan samsung, HTC and ipod what could be the reason? Please help me to resolve thankyou in advance.
code
// object creation
@IBAction func btnScanClicked(sender:UIButton)
{
var centralManager:CBCentralManager = CBCentralManager(delegate: self, queue: nil)
self.centralManager = centralManager
}
// method called whenever the device state changes.
func centralManagerDidUpdateState(central: CBCentralManager!) {
if central.state == CBCentralManagerState.PoweredOff
{
println("bluetooth is off")
}
else if central.state == CBCentralManagerState.PoweredOn
{
central.scanForPeripheralsWithServices(nil, options: nil) // scanning devices
println("bluetooth is on")
}
else if central.state == CBCentralManagerState.Unknown
{
println("bluetooth is unknown")
}
else if central.state == CBCentralManagerState.Unsupported
{
println("bluetooth is unsupported")
}
}
// method to discover peripherals:-
func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!)
{
if peripheral != nil{
println("discovered \(peripheral.name)")
}
else
{
println("No device found")
}
self.peripheral = peripheral
peripheral.delegate = self
central!.connectPeripheral(peripheral, options: nil)
}
// method to connect:-
func centralManager(central: CBCentralManager!, didConnectPeripheral peripheral: CBPeripheral!)
{
peripheral.delegate = self
peripheral.discoverServices(nil)
if ((peripheral) != nil)
{
var state = peripheral.state == CBPeripheralState.Connected ? "yes" : "no"
connected = "Connected \(state)"
println("connected \(connected)")
}
}
Upvotes: 0
Views: 2228
Reputation: 2211
Android OS does not support using the phone as a peripheral, only as a master.
The iPhone will not behave as a peripheral unless it is running software to do so. You can find example code for an iOS device advertising as a peripheral in Apple's BTLE_Transfer sample app available on their developer portal.
Upvotes: 1