0

I would like to implement background bluetooth scanning on IOS. When the application goes in background mode it calls TestCentralManagerDelegate which implements DiscoveredPeripheral function. It is triggered when a new bluetooth peripheral device is detected. If a new bluetooth device is detected the application read the manufacture data which is presented in Dictionary advertisementData (as argument of DiscoveredPeripheral function). The manufacture data are obtained by calling ManufactureData = advertisementData["kCBAdvDataManufacturerData"].ToString(). The discovering of the manufacture data was tested on two different iPhones 5s and 6 with the same iOS 12.1. When the application goes in background mode, I locked the screen. In the case of iPhone 5s, I observed that ManufactureData was found each time the DiscoveredPeripheral function is triggered. This fact is not true for iPhone 6, each time I got ManufactureData = null. It is worth mentioning that the manufacture data are received in both cases if the screen is not locked.

I do not understand why the iPhone 6 does not find ManufactureData, meanwhile the iPhone 5s does. I would accept the fact that phones have different operating systems and this implies different responses, but in my case this is not the case. I will appreciate any help for better understanding aforementioned problem.

Here is code I am using Xamarin.iOS.

public override  void DiscoveredPeripheral(CBCentralManager central, CBPeripheral peripheral, NSDictionary advertisementData, NSNumber RSSI)
        {

            try
            {
                central.StopScan();

                if (peripheral == null || advertisementData == null)
                {
                    central.ScanForPeripherals(cbuuids);
                    return;
                }

                string ManufactureData;

                if (advertisementData.ContainsKey(new NSString("kCBAdvDataManufacturerData")))
                {
                    ManufactureData = advertisementData["kCBAdvDataManufacturerData"].ToString();
                }
                else
                {

                    ManufactureData = null;

                    CrossLocalNotifications.Current.Show("no advertising data", "no advertising data", 10);
                    central.ScanForPeripherals(cbuuids);
                    return;
                }


                central.ScanForPeripherals(cbuuids);
            }
            catch
            {
                central.ScanForPeripherals(cbuuids);
            }

        }
  • I am surprised to hear that you can read the manufacturer data in the background at all. In my previous tests, I have seen this always be nil when the app is in the background (regardless of whether the screen is locked). In my mind the question is why does this work on the 5s? I wonder if it is simply an unintended bug by apple on that device model that is giving you a desirable result? – davidgyoung Nov 27 '18 at 11:27
  • Thanks for reply. Then I have only one solution connecting to the peripheral device and reading data. – Samo Simoncic Nov 27 '18 at 18:51

0 Answers0