Getting a valid CBUUID from a Bluetooth device for scanning - ios

I am writing a simple device browser for a specific kind of Bluetooth device (a card reader). I understand you're supposed to pass in an array of services specified by CBUUIDs to the scanForPeripherals(withServices:options:) method.
To find these IDs, I've scanned without a service filter, found my device, and looked in advertisementData["kCBAdvDataServiceUUIDs"] where I found a single 64-bit CBUUID looking something like this: 0x00000001c413e940.
How do I convert this string into a valid CBUUID that I can pass in as a service filter? I have tried the CBUUID(string:) initialiser, but it just throws a runtime exception saying it's not a valid UUID.
I've also looked in the device's reference manual and found the following table:
However, none of these appear to work - no devices appear in the scan when filtering by these service UUIDs.
Finally, when I examine the device in LightBlue it reports 1 service broadcasting (FFF0), but when I attempt to filter by this service, no devices show.
I'm starting to think the service filter is just plain broken. Does anyone ever actually use it?
Update: It works! I rebuilt and reinstalled the app and the device appeared when scanning with a service filter for FFF0. Thanks Paulw11 for your help.

Related

Discovering services via Bonjour on iOS 14

I'm having trouble understanding privacy constraints for local network service discovery using Bonjour on iOS 14. Here is what I found:
Using NetServiceBrowser, I'm able to discover services using:
browser.searchForServices(ofType: "_services._dns-sd._udp", inDomain: "local.")
I have to add a couple of keys to .plist file, but it works.
However, if I turn to NWBrowser, and try to run the same request, I get an error:
nw_browser_fail_on_dns_error_locked [B1] Invalid meta query type specified.
nw_browser_start_dns_browser_locked failed: BadParam(-65540)
I gather, this means I need the multicast entitlement.
Now, the question is, why would I go through all the trouble of requesting multicast entitlement from Apple, if I just can use NetServiceBrowser instead of NWBrowser? Doesn't NetServiceBrowser defeat the purpose of obtaining multicast entitlement?
According to the docs this error means that you passed an invalid value to NWBrowser - most probably it's the format of the service you're trying to discover.
You haven't posted your NWBrowser code, but for example, a wrong formatted service such as _example_.tcp would probably result in the error you're seeing. Make sure it is in the correct format, which should be something like _example._tcp..
Another thing you need to do is modify your Info.plist file and add two keys:
Bonjour Services - this is an array, the first item should be the service you're trying to discover, in my example, it is _example._tcp.
Privacy - Local Network Usage Description - that one takes an explanation text which will be shown to the user the moment you start discovery with NWBrowser.
Now regarding the entitlement you mentioned: it is only needed for apps that scan for all services on the network and not a specific one like in your case. I encourage you to watch this video, which explains everything I wrote here.
Lastly, why should you use NWBrowser over NetServiceBrowser? That's a very good question which I'm also trying to figure out the answer for 😆
The multicast entitlement is only required if you're scanning for all services. If you're scanning for a specific service - you don't need it
In iOS15 - if you do not have the entitlement you can not do
browser.searchForServices(ofType: "_services._dns-sd._udp", inDomain: "local.")
The reason to use NWBrowser is that it is the new api - NetServiceBrowser is deprecated. At some point - Apple will (probably) simply remove NetServiceBrowser. It's pretty deeply ingrained in a lot of software though - so I don't see them removing it any time soon.
NWBrowser is a somewhat easier API to use as far as straightforward browsing goes.
Note though - that if you want to resolve a service to get an IP address, you'll need to use NetService anyway...

Get list of all wifi available in ios

I have check all possible solutions to get list of all available Wifi's but nothing works for me.
I even try NEHotspotConfigurationManager API but it connect to wifi with predefined SSID. In my case I need to get the list only.
Do we need entitlement document for NEHotspotNetwork?
This is not still possible in iOS. It doesn't look like there's a way to retrieve a list of currently available SSIDs, without using private APIs which would result in rejection from App Store submission of your app.

connectedAccessories method in externalAccessory framework iOS giving 0 elements

This might be a duplicate question, but all previous are asked more than one year ago and does not have helpful answer.
External Accessory Framework bluetooth pair. connectedAccessories every time count 0
iOS External Accessory Framework: how to get a protocol string for certain MFI device
https://apple.stackexchange.com/questions/45398/is-it-possible-to-get-the-api-details-and-protocol-details-from-an-mfi-certified
I want to use external accessory framework to connect my iOS app with mfi devices. I run EADemo app but it requires Supported external accessory protocols strings.
I don't know from where to get this string and what this strings should be. Please help what string should I use to atleast check the sample app. Currently I have iPhones, iPods, bluetooth speakers(bose), and headset.
Please help, I am stuck here.
Thanks in advance!
Any suggestions would be highly appreciated.
Edit 1:
After reading the apple documentation https://developer.apple.com/library/content/featuredarticles/ExternalAccessoryPT/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009498-SW1
it says if trying to communicate with specific accessory, it is required to know the protocol string from manufacturers in order to communicate with it.
but what does this line return:
NSArray *accessories = [[EAAccessoryManager sharedAccessoryManager]
connectedAccessories];
I have connected 2-3 speakers via bluetooth from my phone, so should the above line give me details of connected accessory even if I didn't declare any protocol strings in info.plist as apple says for communication its important to know the protocol but can we see the devices in some list. I am getting 0 elements.
From apple docs:
"This class contains an array of already connected accessory objects that you can enumerate to see if there is one your app supports."
please suggest.
can anyone tell any example accessory name which I should use to check the externalframework working(means giving the accessory as an element)

How to identify a device scanning via bluetooth with other methods

It's not a duplicate of any questions.
I'm creating an app which uses bluetooth to find other users using my app who are near you.
With android it's all right. But if I use iOS, is not possible, because as I've read here in stackoverflow, it's not possible to identify a device via bluetooth scan with something which shall be unique, (and if it exists please let me know!!!!) but let me give you an example of what i'm searching:
If two different people are registered in my app (respectively Robin1 and Robin2) and they have the same name in their bluetooth (for example "Robin's iphone"), there is a way to let me know in my app that the first "Robin's iphone" is "Robin1" (his nickname in my app) and the second "Robin's iphone" is "Robin2"?
The only thing I need is the bluetooth scanning 'cause my app is based of users really near you and GPS is not precise... not yet.
I hope this example is written good :/
Thank you
Strategies for identifying devices have been widely discussed on the bluetooth-dev mailing list and in many Stack Overflow questions as well. For example, check out this discussion: http://lists.apple.com/archives/bluetooth-dev/2013/Nov/msg00071.html
For simplicity here are two options:
Set the user name to be advertised by the CBAdvertisementDataLocalNameKey in the startAdvertising: call. Though, this is a very brittle solution.
More robust is to connect to the discovered peripheral and read a characteristic that your application includes to expose the user identifier.
Note that you cannot rely on using the CBPeripheral.identifier for identification as it is going to be a different random value on every device that discovers the peripheral. Also note that if you plan on using backgrounded operation, then that will require special care as many restrictions kick in when the app goes to background.

iOS hardware parameters for unique id generation

Hi I would like to generate an unique id for an iOS device using any of the device hardware parameters. I do not want to use the MAC address because there is a chance that the MAC address can also be changed. So can you please let me know if there is any other unique hardware parameter with which I can generate an unique ID.
I believe something along the lines of this is the generally accepted replacement for UUID.
In short, you need to create a CFUUID, and then store it in the Keychain on the iOS device, which persists even if you uninstall the app. Having written my own implementation along those lines (not the one I've linked to, obviously), I've yet to come across any real problems with this. It can even be accessed in your other apps that you make, so long as you access it with the same security parameters in aloof your apps.

Resources