0
votes

I made a ibeacon project, now I found two problems: first,when mobile phone lock screen, I'm going to scan for Bluetooth devices (I'm sure in the beacon region), sometimes Scan failed and returned empty array second, when I lock screen, sometimes didEnterRegion and didExitRegion have stopped, when I am the light of the screen, they went on again

Now I want to scan the device every time when I lock the screen,what should i do?

MonitoringForRegions code:

                let region = BRTBeaconRegion.init(proximityUUID: proxiID, identifier: proxiID.UUIDString)

                region.notifyOnEntry = true
                region.notifyOnExit = true
                region.notifyEntryStateOnDisplay = true
                BRTBeaconSDK.startMonitoringForRegions(region)

Appdelegate delegate code:

 func beaconManager(manager:BRTBeaconManager,didEnterRegion region:BRTBeaconRegion){
    if region.notifyOnEntry {
        //PublicMethod().sendLocalNotification(BEACON_TIP_IN)

        print("\(NSDate())-------enter--------")

    }
}

func beaconManager(manager:BRTBeaconManager,didExitRegion region:BRTBeaconRegion){
    if region.notifyOnExit {
        //PublicMethod().sendLocalNotification(BEACON_TIP_OUT)
        print("\(NSDate())-------exit--------")

    }
}
func beaconManager(manager:BRTBeaconManager,didDetermineState state:CLRegionState,forRegion region:BRTBeaconRegion){
    print("didDetermineState")

}

scan code:

     BRTBeaconSDK .startRangingBeaconsInRegions(regionArray) { (beacons, region, error ) in
        for beacon in beacons as! [BRTBeacon]{
            print("beacons count:\(beacons.count)  name :\(beacon.name)   macaddress:\(beacon.macAddress)  major:\(beacon.major)  minor:\(beacon.minor) ")
        }
    }

updated at 14:25 I found the first problem more accurately described, when the lock screen, the device is close to the phone, can be scanned, but not far away (this distance can be scanned at the front desk)

So I guess if the scanning distance is not accurate when lock screen?

1
I would suggest you post code of what you have so far so people can help you betterYoun Elan

1 Answers

1
votes
  1. Did you turn on the Background Modes for Bluetooth in the Xcode project's capabilities page?

https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html

  1. You need to first understand the mechanism of CoreBluetooth. Especially you need to understand the different between Ranging and Monitoring, and the limitations of them in background mode. Some operations can only be achieved in the foreground mode.

Detecting beacons via iBeacon Monitoring & Ranging vs CoreBluetooth scanForPeripheralsWithServices

  1. didEnterRegion and didExitRegion is not realtime, there is buffer time in between exit and reenter the region. Also, if you are already in the region before you call the monitor function, the didEnterRegion won't be trigged.

Update

1、Not open ,Before trying to open, or have the same problem

You need to turn it on, and do some settings in order to implement background scanning.

2、Thank you very much, but I found the scan failed, not every time, occasionally.That's what I don't understand.

3、yes,My experiments are the first to leave the area, then enter the area, because I have two beacon equipment together, UUID is different, close one, then I went to scan, and then found sometimes does not scan, sometimes it is possible

I cant find the code of the Bluetooth library that you are using. It seems like it is written by Mainland China developer? Can you post the link of that library?

My exp, the CoreBluetooth ranging functions are quite reliable. So I guess the problem is you didnt turn on the background mode. Turn on Acts as a Bluetooth LE accessory and Uses Bluetooth LE accessories in the Capabilities tab.

Also, I suggest you to read / bookmark Radius Networks's blog. Their developer blog is worth reading.

http://developer.radiusnetworks.com/2014/11/13/extending-background-ranging-on-ios.html