ibeacon - Swift2.3 code for Beacon detection -
we in advanced stages of developing swift2.2 app , hence have decided migrate 2.3 in interim , full swift 3 migration later. unable beacon detection working post conversion swift 2.3. method "didrangebeacons" keeps returning empty array. same code working in swift 2.2 know have permissions etc in place.
also if open "locate" app on same ipad our app starts returning data in "didrangebeacons". have tried various versions of apps out there , swift2.3 apps behaving same way. can't make out locate app doing... on same boat??
here code using. not sure supposed written here or in comments couldn't put code within comments somehow...
import uikit import corelocation class viewcontroller: uiviewcontroller, cllocationmanagerdelegate { let locationmanager = cllocationmanager() let region = clbeaconregion(proximityuuid: nsuuid(uuidstring: "9735bf2a-0bd1-4877-9a4e-103127349e1d")!, identifier: "testing") // note: make sure replace keys here own beacons' minor values override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. self.locationmanager.delegate = self self.locationmanager.requestalwaysauthorization() self.locationmanager.startmonitoringforregion(self.region) } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } func locationmanager(manager: cllocationmanager, didstartmonitoringforregion region: clregion) { print("didstartmonitoringforregion") self.locationmanager.requeststateforregion(region) } func locationmanager(manager: cllocationmanager, monitoringdidfailforregion region: clregion?, witherror error: nserror) { print("monitoringdidfailforregion") } func locationmanager(manager: cllocationmanager, diddeterminestate state: clregionstate, forregion region: clregion) { print("diddeterminestate") if state == .inside { //start ranging self.locationmanager.startrangingbeaconsinregion(self.region) self.locationmanager.startupdatinglocation() } else { //stop ranging here self.locationmanager.stopupdatinglocation() self.locationmanager.stoprangingbeaconsinregion(self.region) } } func locationmanager(manager: cllocationmanager, didrangebeacons beacons: [clbeacon], inregion region: clbeaconregion) { print(beacons.count) }
}
[update post more attempts working] app works in foreground mode if remove self.locationmanager.startmonitoringforregion(self.region) , call self.locationmanager.startrangingbeaconsinregion(self.region) directly after self.locationmanager.requestalwaysauthorization()
this sub-optimal because don't entry , exit events or state atleast getting beacon counts.
there number of anecdotal reports of beacon detection problems on ios 10. symptoms include:
- improper region exit events, when app in background, followed entry events if shoulder button pressed.
- periodic dropouts in detections of ranged beacons, callbacks providing empty beacon list when beacons in vicinity.
- ranged beacon callbacks return proper results when different beacon ranging or detection app running targets ios 9.x.
this presumably bug fixed in ios update. until then, users have reported setting app deployment target in xcode 9.x resolve issue.
Comments
Post a Comment