显示来自信标的数据

问题描述 投票:0回答:2

我正在使用本机应用程序来使用apple的iBeacon框架,并尝试在控制台上记录我附近所有bluetoooth设备的列表。我一直关注this tutorial但是当我运行应用程序时,没有任何内容打印到控制台。我的错误在哪里?

下面是我编写的视图控制器文件的完整细节:

import UIKit
import CoreLocation


class ViewController: UIViewController, CLLocationManagerDelegate {

let locationManager = CLLocationManager()
let region = CLBeaconRegion(proximityUUID: NSUUID(uuidString: "852c0828-fe67-4dd7-b8ff-52852a66851e")! as UUID, major: 8008, minor: 1337, identifier: "Testing")


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    locationManager.delegate = self

    if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.authorizedWhenInUse) {
        locationManager.requestWhenInUseAuthorization()
    }

    locationManager.startRangingBeacons(in: region)
}

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

func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
    print(beacons)
    print("hello")
    }
 }

在运行时没有任何内容打印到控制台,包括“你好”。

ios swift ibeacon
2个回答
1
投票

代码看起来不错。你确定你知道你的信标标识符并且它正在传输吗?

我会尝试使用现成的信标检测器应用程序,如Locate,以验证它可以看到你的灯塔。请注意,您必须在应用程序中配置信标UUID以进行检测。

其他一些提示:

  • 确保您的Info.plist包含这样的条目,否则它将无法提示您进行位置访问:<key>NSLocationWhenInUseUsageDescription</key><string>This app needs to access your location so it can tell when you are near a beacon.</string>
  • 确保提示您输入位置,并且实际上已授予它。检入设置 - > [您的应用程序名称] - >位置,并验证它是否显示“允许位置访问”具有不在“从不”旁边的复选标记。
  • 确保蓝牙已开启。

0
投票
  1. 首先检查用于创建CLBeaconRegion的已配置proximityUUID是否正确。
  2. 您指定的信标应该处于活动状态,这意味着它不应该被放电,并且它应该是ON,以便当您的设备进入指定的信标区域时,您的设备可以看到它。
  3. 还要检查Info.plist并确保它应该包含NSLocationWhenInUseUsageDescription对。因此,您的应用会提示您进行位置访问,并且您应该允许访问它。
  4. 你的蓝牙应该开启。
© www.soinside.com 2019 - 2024. All rights reserved.