swift - didEnterRegion only gets fired sometimes -


i wrote code below, basic swift 3 code think of in order check if app can detect if ibeacon available. however, didenterregion fired once in blue moon. ran on phone 20 times, , got fired twice. problem not seem beacon itself, when use app app store, detects ibeacon. ideas why callback called? ps: have added privacy - location usage description info.plist

import uikit import corelocation  class viewcontroller: uiviewcontroller {  let locationmanager = cllocationmanager()  @iboutlet weak var textlabel: uilabel!  override func viewdidload() {     super.viewdidload()     locationmanager.requestalwaysauthorization()     locationmanager.delegate = self     // additional setup after loading view, typically nib. }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  @ibaction func startmonitoring(_ sender: any) {     if let uuid = uuid(uuidstring: "10f86430-1346-11e4-9191-0800200c9a66") {         let beaconregion = clbeaconregion(proximityuuid: uuid, major: 1, minor: 1,identifier: "ibeacon")         locationmanager.startmonitoring(for: beaconregion)         textlabel.text = "monitoring"     } } }  extension viewcontroller: cllocationmanagerdelegate { func locationmanager(_ manager: cllocationmanager, monitoringdidfailfor region: clregion?, witherror error: error) {     textlabel.text = "\(error.localizeddescription)" }  func locationmanager(_ manager: cllocationmanager, didfailwitherror error: error) {     textlabel.text = "\(error.localizeddescription)" }  func locationmanager(_ manager: cllocationmanager, didenterregion region: clregion) {         textlabel.text = "found new beacon" } } 

you have exit region, wait 30 secs or , enter again have trigger. if staying in region won't trigger.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -