gpt4 book ai didi

ios - 显示 "Cannot find iBeacon"消息

转载 作者:搜寻专家 更新时间:2023-10-31 22:42:06 25 4
gpt4 key购买 nike

我的问题很简单。在 viewDidLoad

中调用 startSearchingForSessions 之后,通过按下按钮调用 startSearchingForSessions 后,我想显示一条错误消息,即“无法找到 iBeacon”
override func viewDidLoad() {
super.viewDidLoad()

self.locationManager = CLLocationManager()
if self.locationManager.responds(to: #selector(CLLocationManager.requestWhenInUseAuthorization)) {
self.locationManager.requestWhenInUseAuthorization()
}
self.locationManager.delegate = self
self.locationManager.pausesLocationUpdatesAutomatically = false

let uuid = UUID(uuidString: "869A6E2E-AE14-4CF5-8313-8D6976058A7A")
self.beaconRegion = CLBeaconRegion(proximityUUID: uuid!, identifier: "com.dejordan.myapp"
startSearchingForSessions()

}

func startSearchingForSessions() {

// Start looking for the beacons with that UUID and Identifier.
self.locationManager.startMonitoring(for: self.beaconRegion)
self.locationManager.startRangingBeacons(in: self.beaconRegion)
self.locationManager.startUpdatingLocation()

}

然后处理找到的信标:

// Required by the Location Manager.
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
self.locationManager.startRangingBeacons(in: self.beaconRegion)
}

func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
if state == CLRegionState.outside {
print("Cannot Find Beacon")
}
}

// Required by the Location Manager.
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
self.locationManager.stopRangingBeacons(in: self.beaconRegion)
}

// This is called if any beacons are found.
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {

var result = Array<CLBeacon>()
for beacon in beacons {
result.append(beacon)
}

foundBeacons = result
// If we found any, we need to see
// what class they belong to based on information
// from Parse.
self.identifyFoundBeacons()

// We can stop looking for beacons now.
self.locationManager.stopMonitoring(for: self.beaconRegion)
self.locationManager.stopRangingBeacons(in: self.beaconRegion)
self.locationManager.stopUpdatingLocation()

}

我已经实现了委托(delegate)错误方法,试图找到发生这种情况的位置,但到目前为止,在 iBeacon 上浏览成堆的文档时,我一无所获。

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Location manager failed: \(error.localizedDescription)")
}

func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error) {
print("Failed monitoring region: \(error.localizedDescription)")
}

谢谢!

最佳答案

如果您只是想知道何时未检测到信标(相对于查找信标时出现低级别故障),则只需使用以下委托(delegate)方法:

public func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
if state == CLRegionState.outside {
print("Cannot find beacon")
}
}

关于ios - 显示 "Cannot find iBeacon"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44537455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com