New advertisement key CBAdvDataTimestamp?

I discovered tonight in iOS 13 beta 8 that there is a new key and value in the advertisement payload. I didn't notice it before and it very well may have been there prior.


The key is visible when printing out the advertisementData dict, and a typecast passes as TimeInterval


        if let timespan = advertisementData["kCBAdvDataTimestamp"] as? TimeInterval {
            print("Adv date intv \(timespan)")
        }


I didn't see this documented in the API reference under new or old keys. Is this going to be in production? Android API captures timestamp of adv packet since boot--it would be nice to have something similar on iOS (point of reference can be epoch).


These are the values that it was decoding as:


Adv date intv 588221792.199425

Adv date intv 588221793.25799

Adv date intv 588221794.237889

Adv date intv 588221795.255606

Adv date intv 588221796.249666

Adv date intv 588221797.243745


They're nothing close to the epoch or seconds since boot. I got this out of the payload on my polar HR7.


["kCBAdvDataManufacturerData": <6b000900 0000>, "kCBAdvDataTimestamp": 588222227.821503, "kCBAdvDataServiceUUIDs": <__NSArrayM 0x280657cf0>(

Heart Rate

)

, "kCBAdvDataLocalName": Polar H7 --------, "kCBAdvDataIsConnectable": 1, "kCBAdvDataTxPowerLevel": 0]

Answered by GrangerFX in 417672022

The kCBAdvDataTimestamp field is added to the advertisement by iOS. It is just the time stamp of when the advertisement was received and can be converted to a NSDate using:

NSNumber *number = advertisementData["kCBAdvDataTimestamp"];

NSTimeInterval absoluteTime = number.doubleValue;

NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:absoluteTime];

Apple also adds kCBAdvDataRxPrimaryPHY and kCBAdvDataRxSecondaryPHY to the advertisement data. Both are NSNumber values and are set to 0 in all the devices I have seen. Their purpose remains a mystery.

Accepted Answer

The kCBAdvDataTimestamp field is added to the advertisement by iOS. It is just the time stamp of when the advertisement was received and can be converted to a NSDate using:

NSNumber *number = advertisementData["kCBAdvDataTimestamp"];

NSTimeInterval absoluteTime = number.doubleValue;

NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:absoluteTime];

Apple also adds kCBAdvDataRxPrimaryPHY and kCBAdvDataRxSecondaryPHY to the advertisement data. Both are NSNumber values and are set to 0 in all the devices I have seen. Their purpose remains a mystery.

It is always funny when you search the web and Google refers you to a post you made half a year ago. I had overlooked the time since Jan 1, 2001, which initializes to the correct date timestamp. No further hits on the phy keys...


I submitted this Feedback to request the key be added to the API officially: FB7689571


I'm creating a nested struct in CBPeripheral to get at the contents of the advertisementData. The advantage behind [String: Any] is that Apple can stuff what ever they want in there and it doesn't need to be in the documentation, for example the three mentioned keys in this convo. Disadvantage is we have to perform key value lookup and conditional casting. 🙂


I'll post a GIST if I get around to it and will edit this reply.


The PHY is related to Bluetooth 5.0 and chipset support for 2 MB PHY. I'd quote the 5.0 spec, but who wants to download 2000 page pdf and hunt and find. Punch has a good article here if you are interested in learing more about the physical layer: https://punchthrough.com/crash-course-in-2m-bluetooth-low-energy-phy/

New advertisement key CBAdvDataTimestamp?
 
 
Q