Tony,
the code by Jimmy is correct. Just don't forget to stop scanning prior to connecting as otherwise, connecting will become very slow.
You can find official documentation under
================================================
scanForPeripheralsWithServices:options:
Ask the central to scan for peripherals.
- (void)scanForPeripheralsWithServices:(NSArray *)serviceUUIDs options:(NSDictionary *)options;
Parameters
-
serviceUUIDs
-
An array of CBUUIDs the app is interested in.
- options
-
A dictionary to customize the scan, see CBCentralManagerScanOptionAllowDuplicatesKey.
Discussion
The relevant delegate callback will be invoked for each discovered peripheral. An array of CBUUIDs may be provided in "serviceUUIDs", in which case the central will only return peripherals
that advertise this/these service(s) (recommended). If nil , all discovered peripherals will be returned (not recommended). If the central is already scanning with different
parameters, the provided parameters will replace them.
Availability
- Available in iOS 5.0 and later.
See Also
CBCentralManagerScanOptionAllowDuplicatesKey
Declared In
================================================
The CBCentralManagerScanOptionAllowDuplicatesKey itself is declared in
CBCentralManager.h.
I recommend looking at the header files directly in addition to the official documentation, because not everything of the CoreBluetooth framework is covered properly on the website.
Note that meanwhile you can shorten the proposed code by Jimmy by using the new syntax for arrays, dictionaries and numbers.
- (void)startScanningForUUIDString:(NSString *)uuidString
{
assert(uuidString);
assert(centralManager);
NSArray *uuidArray = @[uuidString];
NSDictionary *options = @{CBCentralManagerScanOptionAllowDuplicatesKey: @YES}; // may have to use @(YES) with brackets under iOS 5
[centralManager scanForPeripheralsWithServices:uuidArray options:options];
}
Etan
Hi tony,
here is how I do it:
- (void) startScanningForUUIDString:(NSString *)uuidString
{
NSArray *uuidArray = [NSArray arrayWithObjects:[CBUUID UUIDWithString:uuidString], nil];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
[centralManager scanForPeripheralsWithServices:uuidArray options:options];
}
You can change the ":YES" to ":NO" if you do not want duplicates!
Br,
Jimmy
On Jan 9, 2013, at 2:11 PM, BAYLEY, Tony wrote:
Hi Etan
Can you explain how to configure to receive multiple advertisements for the same device, or tell me where to look in the documentation? I could not find out how to do this, so perform multiple short scans to receive updates to dynamic data that is contained
in the advertisement packets.
Best regards
Tony.
-----Original Message-----
From:
bluetooth-dev-bounces+antony.bayley=email@hidden [mailto:bluetooth-dev-bounces+antony.bayley=email@hidden] On Behalf Of Etan Kissling
Sent: 09 January 2013 12:48
To: Jimmy Adler
Cc: <email@hidden>
Subject: Re: Is it possible to change scan parameters for BT LE scans?
Jimmy,
one more update for my last message:
The only scanning option that you have on iOS is whether you want to receive multiple advertisements for the same device.
If this is disabled, I'm not sure whether or not SCAN_RSP data is already included when the first advertisement is received.
Note that background scanning will always only send the first advertisement for each device to your app.
Regarding device name in SCAN_RSP data:
A video of one of the projects I worked for in action, where the peripheral name is broadcasted as SCAN_RSP data, can be watched under the following link. Note how it takes several seconds for all the names to load, even after the peripheral has already been
discovered.
http://www.youtube.com/watch?v=uqGF-Mtja-E&feature=player_embedded
(device list starts at 0:20)
Etan
On 09.01.2013, at 11:15, Etan Kissling <email@hidden>
wrote:
You cannot specify scanning options on iOS using public APIs. However, iOS supports active scanning.
Note that you should put static data in your scan_rsp part as additional packets have to be exchanged to retrieve them. Dynamic data should be put in your advertisement data.
I have not tested it but it may be reasonable that iOS does not send a SCAN_REQ for each and every advertisement report of the same device. Also, as the SCAN_RSP data arrives at a later point in time than the original advertisement data, you may not see it
at all.
What I tested in the SCAN_RSP data until now is only a partial device name. This works perfectly (but is not available on the first received advertisement yet) and is overridden as soon as you connect to the device with the name stored in the GAP service.
As the name is managed by iOS, other rules may apply for custom SCAN_RSP data.
I also suggest using the TI packet sniffer for ~50$ to see when the iphone actually sends these scan_req packets.
Etan
On 09.01.2013, at 09:59, "Jimmy Adler" <email@hidden> wrote:
I have an issue detecting kCBAdvDataManufacturerData from a 3:rd party device using BT LE. I get the kCBAdvDataLocalName advertisement, but not the one containing the Data.
When using a PC testapplication I'm able to get the kCBAdvDataManufacturerData by setting the scan_interval to 10ms and scan_window to 10ms and using active scanning.
Problem is that as far as I can see, these parameters are not accessible on the IOS device, or can the paramters be sent in when starting the scan using the options dictionary in some way?
Is this problem solvable without having access to and altering the code in the device?
Best regards,
Jimmy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
on.ch
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:
n.ch
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
________________________________
CONFIDENTIALITY NOTICE: This e-mail transmission, and any documents, files or previous e-mail messages attached to it, may contain information that is confidential and/or legally privileged. If you are not the intended recipient, or a person responsible for
delivering it to the intended recipient, please DO NOT disclose the contents to another person, store or copy the information in any medium, or use any of the information contained in or attached to this transmission for any purpose. If you have received this
transmission in error, please immediately notify the sender by reply email or at email@hidden, and destroy the original transmission and its attachments without reading or saving in any manner.
For further information about Plantronics - the Company, its products, brands, partners, please visit our website www.plantronics.com.
|