• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Trouble scanning for peripherals - iOS 8 + Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble scanning for peripherals - iOS 8 + Swift


  • Subject: Re: Trouble scanning for peripherals - iOS 8 + Swift
  • From: Tian Zhang <email@hidden>
  • Date: Thu, 25 Sep 2014 20:49:24 -0700

You used wrong delegate callback … Correct method signature should be 
func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!)
instead of 
func didDiscoverPeripheral(peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!)

Best Wishes,
Tian

On Sep 25, 2014, at 8:26 PM, Peter Watkins <email@hidden> wrote:

I wrote a dirt-simple single view app to scan for peripherals and NSLog them. LightBlue sees the peripheral, by the way. This is on an iPhone 5s running iOS 8.0.

CoreBluetooth goes to the PowerOn state and start the scan, but didDiscoverPeripheral is never called. Everything is in my view controller, so here's the entire code: Any idea why didDiscoverPeripheral is never called? Did I miss something obvious?

import UIKit
import CoreBluetooth

class ViewController: UIViewController, CBCentralManagerDelegate {

    

    var centralManager: CBCentralManager!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        

        self.centralManager = CBCentralManager(delegate:self, queue:nil)
    }

    

    func centralManagerDidUpdateState(central: CBCentralManager!) {
        NSLog("\(central.state)");

        

        if (central.state == CBCentralManagerState.PoweredOn) {
            centralManager.scanForPeripheralsWithServices(nil, options:[CBCentralManagerScanOptionAllowDuplicatesKey:true])
        }
    }

    

    func didDiscoverPeripheral(peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) {
        NSLog("Discovered \(peripheral.description)")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

Thanks,

Peter
Do not post admin requests to the list. They will be ignored. Bluetooth-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Trouble scanning for peripherals - iOS 8 + Swift (From: Peter Watkins <email@hidden>)

  • Prev by Date: Trouble scanning for peripherals - iOS 8 + Swift
  • Next by Date: Re: Trouble scanning for peripherals - iOS 8 + Swift
  • Previous by thread: Trouble scanning for peripherals - iOS 8 + Swift
  • Next by thread: Re: Trouble scanning for peripherals - iOS 8 + Swift
  • Index(es):
    • Date
    • Thread