• 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: How to get the updated advertisementData (kCBAdvDataManufacturerData) value?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value?


  • Subject: Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value?
  • From: Christopher Cotton <email@hidden>
  • Date: Fri, 16 Jan 2015 20:54:12 -0600

I think one issue with that code, is that you aren't keeping a
reference the peripheral.

Here is a sample file that works, I tested it on our device. We are
not connecting to the device, just scanning. Our advertisement data
change when you press a button to let the app know which device was
just pressed.

https://gist.github.com/christophercotton/0993c9702b416dcee242


import UIKit

import  CoreBluetooth


class ViewController: UIViewController, CBCentralManagerDelegate,
CBPeripheralDelegate {

    var centralManager:CBCentralManager!

    var queue:dispatch_queue_t!

    var datas = [String : String]()

    var peripherals = [CBPeripheral]()



    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.

        queue = dispatch_queue_create("MyBLE", DISPATCH_QUEUE_SERIAL)

        centralManager = CBCentralManager(delegate: self, queue: queue);

    }



    func centralManager(central: CBCentralManager!,
didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData:
[NSObject : AnyObject]!, RSSI: NSNumber!) {



        if (!contains(peripherals, peripheral)) {

            peripherals.append(peripheral)

        }



        let key = peripheral.identifier.UUIDString

        let data = advertisementData.description



        if let previous = datas[key] {

            if (previous != data) {

                println("Different \(peripheral.name): \(data)")

            }

        } else {

            println("\(peripheral.name): \(data)");

            datas[key] = data

        }



    }



    func centralManagerDidUpdateState(central: CBCentralManager!) {

        println("centralManagerDidUpdateState");

        if (central.state == .PoweredOn ) {

            println("Scanning")

            centralManager.scanForPeripheralsWithServices(nil,
options:[CBCentralManagerScanOptionAllowDuplicatesKey:true]);

        }

    }

}



On Fri, Jan 16, 2015 at 1:48 PM, Hank Li <email@hidden> wrote:
> Here is my testing code to get the advertisement data, the repeat scan does
> not get the updated advertisement data.
>
> import UIKit
> import  CoreBluetooth
>
> class ViewController: UIViewController, CBCentralManagerDelegate,
> CBPeripheralDelegate {
>     var centralManager:CBCentralManager!
>     override func viewDidLoad() {
>         super.viewDidLoad()
>         // Do any additional setup after loading the view, typically from a
> nib.
>         centralManager = CBCentralManager(delegate: self, queue: nil);
>     }
>     override func viewWillAppear(animated: Bool) {
>         NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector:
> Selector("startScan"), userInfo: nil, repeats: true);
>     }
>     override func didReceiveMemoryWarning() {
>         super.didReceiveMemoryWarning()
>     }
>     func startScan() {
>         println("startScan");
>         centralManager.scanForPeripheralsWithServices(nil, options: nil);
>         NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector:
> Selector("stopScan"), userInfo: nil, repeats: false);
>     }
>     func stopScan() {
>         println("stopScan");
>         centralManager.stopScan();
>     }
>     func centralManager(central: CBCentralManager!, didDiscoverPeripheral
> peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI:
> NSNumber!) {
>         println("\(peripheral.name): \(advertisementData)");
>     }
>     func centralManagerDidUpdateState(central: CBCentralManager!) {
>         println("centralManagerDidUpdateState");
>     }
> }
>
>
>
>
> Thanks,
> Hank Li
>
>
>
> On Fri, Jan 16, 2015 at 10:46 AM, Hank Li <email@hidden> wrote:
>>
>> Hi, Chris:
>>
>> can you email me your test app? I'd like to test it on my phone.
>>
>>
>> Thanks,
>> Hank Li
>>
>>
>>
>> On Fri, Jan 16, 2015 at 7:32 AM, Christopher Cotton
>> <email@hidden> wrote:
>>>
>>> I'll have to write a short simple app to demonstrate. But, we change
>>> our manufacturer data and haven't had any issue with caching. The
>>> change shows up almost immediately. We don't have to connect to it
>>> either.
>>>
>>> Which part of the data are you changing?
>>>
>>>
>>>
>>> On Fri, Jan 16, 2015 at 9:20 AM, Zach Dennis <email@hidden>
>>> wrote:
>>> > iOS caching will be problematic for purely advertisement data changes.
>>> > We
>>> > have seen related issues as well where it will cache advertisement data
>>> > based on the advertiser's address in the advertisement. We have a
>>> > switch
>>> > that causes a BLE device to act as different devices when toggled, but
>>> > iOS
>>> > caching causes an issue.
>>> >
>>> > Our resolution so far is to have the user toggle wifi on and off which
>>> > seems
>>> > to force the iOS BLE cache to be cleared.
>>> >
>>> > One thing to try if you own the firmware code on the BLE device is to
>>> > change
>>> > the advertiser address whenever you change advertising data, then iOS
>>> > will
>>> > think it sees a new device. But, that may defeat whatever it is you're
>>> > trying to do. I'm assuming you're trying to avoid making the device
>>> > connectable.
>>> >
>>> > Zach
>>> >
>>> > On Fri, Jan 16, 2015 at 6:09 AM, David Chu <email@hidden>
>>> > wrote:
>>> >>
>>> >> Hey Hank,
>>> >>
>>> >> I believe this is the problem.
>>> >>
>>> >> CoreBluetooth only discovers a device once and then caches the data to
>>> >> save energy. In order to keep getting the updated data you would need
>>> >> to do
>>> >> one of two things.
>>> >>
>>> >> - Connect to the device and then ask for an update of the advertising
>>> >> data.
>>> >> It seems this is what you are avoiding.
>>> >>
>>> >> - Stop stop and restart your scan. (perhaps on a time delay? I have
>>> >> never
>>> >> stopped and restarted a scan right after each other. But I can confirm
>>> >> that
>>> >> restarting the scan will make the device discoverable again).
>>> >>
>>> >> Dave
>>> >>
>>> >>
>>> >> On Jan 16, 2015, at 10:52 AM, Hank Li <email@hidden> wrote:
>>> >>
>>> >> The peripheral is saved. the issue is that when the advertisement data
>>> >> is
>>> >> changed on the device, the ios app could not get the updated value. It
>>> >> seems
>>> >> the ios cached the advertisementdata.
>>> >>
>>> >>
>>> >> Thanks,
>>> >> Hank Li
>>> >>
>>> >>
>>> >>
>>> >> On Thu, Jan 15, 2015 at 5:05 PM, Christopher Cotton
>>> >> <email@hidden> wrote:
>>> >>>
>>> >>> We use changing advertisement data just fine in our iOS app. Are you
>>> >>> keeping a reference to the peripheral that is given to you? you
>>> >>> should
>>> >>> get a ton of logs. You need to keep a reference otherwise it discards
>>> >>> that peripheral as per the docs in the header:
>>> >>>
>>> >>>
>>> >>>      *  @discussion                 This method is invoked while
>>> >>> scanning, upon the discovery of <i>peripheral</i> by <i>central</i>.
>>> >>> A
>>> >>> discovered peripheral must
>>> >>>
>>> >>>      *                              be retained in order to use it;
>>> >>> otherwise, it is assumed to not be of interest and will be cleaned up
>>> >>> by the central manager.
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>> On Thu, Jan 15, 2015 at 6:33 PM, Hank Li <email@hidden> wrote:
>>> >>> > For my IOS app (on ios8), once it get the advertisementData, it
>>> >>> > will
>>> >>> > stay
>>> >>> > the same, even the data has been changed on the BLE device. How can
>>> >>> > I
>>> >>> > get
>>> >>> > the updated advertisementData in my ios app?
>>> >>> >
>>> >>> > Here is the code, the startScan is called every 5 seconds.
>>> >>> >
>>> >>> > func startScan() {
>>> >>> > let opts = [CBCentralManagerScanOptionAllowDuplicatesKey:true];
>>> >>> > centralManager.scanForPeripheralsWithServices(nil, options:opts);
>>> >>> > }
>>> >>> >
>>> >>> > func centralManager(central: CBCentralManager!,
>>> >>> > didDiscoverPeripheral
>>> >>> > peripheral: CBPeripheral!, advertisementData: [NSObject :
>>> >>> > AnyObject]!,
>>> >>> > RSSI:
>>> >>> > NSNumber!) {
>>> >>> >         println("\(advertisementData)");
>>> >>> > }
>>> >>> >
>>> >>> > Here is the output,
>>> >>> >  [kCBAdvDataLocalName: MyDevice001, kCBAdvDataIsConnectable: 1,
>>> >>> > kCBAdvDataManufacturerData: <11e467f7 7ec2ed>]
>>> >>> >
>>> >>> > the output will never change. how to get the updated
>>> >>> > advertisementData
>>> >>> > value?
>>> >>> >
>>> >>> > Thanks,
>>> >>> > Hank Li
>>> >>> >
>>> >>> >
>>> >>> >
>>> >>> >  _______________________________________________
>>> >>> > 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
>>> >>>
>>> >>>
>>> >>>
>>> >>> --
>>> >>> Christopher
>>> >>
>>> >>
>>> >> _______________________________________________
>>> >> 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
>>> >>
>>> >>
>>> >>
>>> >>  _______________________________________________
>>> >> 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
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > @zachdennis
>>> > http://www.continuousthinking.com
>>> > http://www.mutuallyhuman.com
>>>
>>>
>>>
>>> --
>>> Christopher
>>
>>
>



--
Christopher
 _______________________________________________
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


  • Follow-Ups:
    • Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value?
      • From: Hank Li <email@hidden>
References: 
 >How to get the updated advertisementData (kCBAdvDataManufacturerData) value? (From: Hank Li <email@hidden>)
 >Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value? (From: Christopher Cotton <email@hidden>)
 >Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value? (From: Hank Li <email@hidden>)
 >Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value? (From: David Chu <email@hidden>)
 >Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value? (From: Zach Dennis <email@hidden>)
 >Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value? (From: Christopher Cotton <email@hidden>)
 >Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value? (From: Hank Li <email@hidden>)
 >Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value? (From: Hank Li <email@hidden>)

  • Prev by Date: Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value?
  • Next by Date: Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value?
  • Previous by thread: Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value?
  • Next by thread: Re: How to get the updated advertisementData (kCBAdvDataManufacturerData) value?
  • Index(es):
    • Date
    • Thread