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
Post a Comment