gpt4 book ai didi

ios - 无法在我的 iOS 应用程序中检测到 Kontakt.io 信标

转载 作者:可可西里 更新时间:2023-11-01 02:13:34 25 4
gpt4 key购买 nike

我已经按照下面的 Kontakt SDK 示例代码编写了信标搜索代码。但是我的信标计数始终为 0,而我的 iPhone 附近有 11 个信标。任何人都可以帮助我解决这个问题吗?

我在 viewDidLoad 方法中初始化了 KTKBeaconManager,然后创建了区域对象并停止了之前的任何测距服务,然后开始了新的监控和测距服务。

而且它一直调用 didRangeBeacons,信标计数 = 0。不确定到底是什么问题。它的代码与他们的示例代码相同。

import UIKit
import KontaktSDK

class ViewController: UIViewController {

var beaconManager: KTKBeaconManager!
@IBOutlet var statusLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()

// Initiate Beacon Manager
beaconManager = KTKBeaconManager(delegate: self)
beaconManager.requestLocationAlwaysAuthorization()

// Region
let proximityUUID = NSUUID(uuidString: "f7826da6-4fa2-4e98-8024-bc5b71e0893e")
let region = KTKBeaconRegion(proximityUUID: proximityUUID! as UUID, identifier: "com.weenggs.KontaktDemo")

// Region Properties
region.notifyEntryStateOnDisplay = true

beaconManager.stopMonitoringForAllRegions()

// Start Ranging
beaconManager.startMonitoring(for: region)
beaconManager.startRangingBeacons(in: region)
beaconManager.requestState(for: region)

// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}
extension ViewController: KTKBeaconManagerDelegate {

func beaconManager(_ manager: KTKBeaconManager, didDetermineState state: CLRegionState, for region: KTKBeaconRegion) {
print("Did determine state \"\(state.rawValue)\" for region: \(region)")
statusLabel.text = "Did determine state \"\(state.rawValue)\" for region: \(region)"
}

func beaconManager(_ manager: KTKBeaconManager, didChangeLocationAuthorizationStatus status: CLAuthorizationStatus) {
print("Did change location authorization status to: \(status.rawValue)")
statusLabel.text = "Did change location authorization status to: \(status.rawValue)"
if status == .authorizedAlways{

// Region
let proximityUUID = NSUUID(uuidString: "f7826da6-4fa2-4e98-8024-bc5b71e0893e")
let region = KTKBeaconRegion(proximityUUID: proximityUUID! as UUID, identifier: "com.weenggs.KontaktDemo")

// Region Properties
region.notifyEntryStateOnDisplay = true

beaconManager.startMonitoring(for: region)
beaconManager.startRangingBeacons(in: region)
beaconManager.requestState(for: region)
}
}

func beaconManager(_ manager: KTKBeaconManager, monitoringDidFailFor region: KTKBeaconRegion?, withError error: Error?) {
print("Monitoring did fail for region: \(region)")
print("Error: \(error)")
statusLabel.text = "Monitoring did fail for region: \(region)"
}

func beaconManager(_ manager: KTKBeaconManager, didStartMonitoringFor region: KTKBeaconRegion) {
print("Did start monitoring for region: \(region)")
statusLabel.text = "Did start monitoring for region: \(region)"
}

func beaconManager(_ manager: KTKBeaconManager, didEnter region: KTKBeaconRegion) {
print("Did enter region: \(region)")
statusLabel.text = "Did enter region: \(region)"
}

func beaconManager(_ manager: KTKBeaconManager, didExitRegion region: KTKBeaconRegion) {
print("Did exit region \(region)")
statusLabel.text = "Did exit region \(region)"
}

func beaconManager(_ manager: KTKBeaconManager, didRangeBeacons beacons: [CLBeacon], in region: KTKBeaconRegion) {
print("Did ranged \"\(beacons.count)\" beacons inside region: \(region)")
statusLabel.text = "Did ranged \"\(beacons.count)\" beacons inside region: \(region)"
if let closestBeacon = beacons.sorted(by: { $0.0.accuracy < $0.1.accuracy }).first , closestBeacon.accuracy > 0 {
print("Closest Beacon is M: \(closestBeacon.major), m: \(closestBeacon.minor) ~ \(closestBeacon.accuracy) meters away.")
statusLabel.text = "\(statusLabel.text) Closest Beacon is M: \(closestBeacon.major), m: \(closestBeacon.minor) ~ \(closestBeacon.accuracy) meters away."
}
}
}

最佳答案

我估计常见的问题是你忘了设置

Kontakt.setAPIKey("yourSuperSecretAPIKey")

以及这两个权限中的任何一个

 NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription

如果不是这种情况,那么您的信标电池可能会耗尽。

关于ios - 无法在我的 iOS 应用程序中检测到 Kontakt.io 信标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40018054/

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