请注意:
- I have an array of custom beacon objects (consumed from API)
For each custom beacon object I create an instance of
CLBeaconRegion
like so:let beaconRegion = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: region.uuid)!, identifier: region.uuid) beaconRegion.notifyOnEntry = true beaconRegion.notifyOnExit = true beaconRegion.notifyEntryStateOnDisplay = true
Then I pass that instance to CLLocationManager's
startMonitoringForRegion
method like so:locationManager.startMonitoringForRegion(beaconRegion)
monitoredRegions
方法响应时,我得到了所有我期望的信标区域,并且它们的regionState为2(外部)。
除此之外,我已经添加了:
NSLocationAlwaysUsageDescription
到应用程序的Info.plist中。
locationManager.requestAlwaysAuthorization()
对于ViewController的viewDidLoad方法来说
然而,只有当我在范围内时,才会触发didEnterRegion和didExitRegion这两个方法,而我开始监测的前三个信标区域中的任何一个都可以。
谢谢,
Piotr Czarnoleski