ios - iBeacons 在 iOS 10.0.2 中损坏?

标签 ios core-location ibeacon core-bluetooth

到目前为止,每个人在 iOS 10.0.2 上使用 iBeacons 的情况如何?希望比我好! :-)

更新:用于测试的硬件是两部 iPhone。 iPhone 5S(A1533) 和 iPhone 7(A1778)

以下代码的 swift 2.x 版本可以在 iPhone 上使用,以在 iOS 9.x 版本上宣传一个简单的 iBeacon;今天,同样的代码——为 swift 3 更新并在 iOS 10.0.2 上运行——似乎根本没有做广告。

我已将代码缩减为一个非常简单的帮助器类和一个我认为应该足以说明问题的 View Controller 。请注意, Storyboard只有一个按钮连接到开始/停止 iBeacon 广告。

我已经在装有 iOS 10.0.2 的 iPhone 5 和 iPhone 7 上运行了该应用程序。为了进行测试,我创建了一个自定义扫描器(嗅探特定的邻近 UUID),当它不起作用时,我尝试了更通用的 iBeacon 检测应用程序,例如 Estimote 和 LightBlue。

唉——什么都看不到 iBeacon。

想法? Apple 的开发者论坛提到了 10.x 中 iBeacons 报告的问题,但据我所知没有一个这么简单。

非常感谢...

- - - iBeaconConfiguration.swift - - - - - -

import Foundation

class iBeaconConfiguration
{
    static let uuid = UUID(uuidString: "F34A1A1F-500F-48FB-AFAA-9584D641D7B1")!

    private init() {}
}

- - - ViewController.swift - - - - - -

import UIKit
import CoreLocation
import CoreBluetooth

class ViewController: UIViewController, CBPeripheralManagerDelegate 
{

    @IBOutlet weak var btnAction: UIButton!

    let UUID: UUID = iBeaconConfiguration.uuid

    var beaconRegion: CLBeaconRegion!

    var dataDictionary = NSDictionary()

    var bluetoothPeripheralManager: CBPeripheralManager!

    var isBroadcasting = false

    override func viewDidLoad() {
        super.viewDidLoad()

        bluetoothPeripheralManager = CBPeripheralManager(delegate: self, queue: nil, options: nil)
    }


    @IBAction func switchBroadcastingState(_ sender: AnyObject) 
    {

    if !isBroadcasting {
        if bluetoothPeripheralManager.state == CBManagerState.poweredOn {

            let major: CLBeaconMajorValue = 123
            let minor: CLBeaconMinorValue = 456

            beaconRegion = CLBeaconRegion(proximityUUID: UUID, major: major, minor: minor, identifier: "com.rdz.bcast")

            dataDictionary = beaconRegion.peripheralData(withMeasuredPower: nil)

            bluetoothPeripheralManager.startAdvertising(dataDictionary as? [String : Any])

            btnAction.setTitle("Stop", for: UIControlState.normal)

            isBroadcasting = true
        }
    }
    else {
        bluetoothPeripheralManager.stopAdvertising()

        btnAction.setTitle("Start", for: UIControlState.normal)

        isBroadcasting = false
    }
}

func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) {

    print ("peripheralManagerDidStartAdvertising()")

    if error != nil
    {
        print(error)
    }
}

func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveRead request: CBATTRequest) {
    print ("peripheralManager(...didReceiveRead)")
}

func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
    var statusMessage = ""

    switch peripheral.state {
    case CBManagerState.poweredOn:
        statusMessage = "Bluetooth Status: Turned On"

    case CBManagerState.poweredOff:
        if isBroadcasting {
            switchBroadcastingState(self)
        }
        statusMessage = "Bluetooth Status: Turned Off"

    case CBManagerState.resetting:
        statusMessage = "Bluetooth Status: Resetting"

    case CBManagerState.unauthorized:
        statusMessage = "Bluetooth Status: Not Authorized"

    case CBManagerState.unsupported:
        statusMessage = "Bluetooth Status: Not Supported"

    default:
        statusMessage = "Bluetooth Status: Unknown"
    }

        print("Bluetooth Status: \(statusMessage)")
    }
}
- - - END - - - - -

(对任何代码格式错误表示歉意。)

最佳答案

很多人报告 iOS 10 上的蓝牙有问题,但问题并不普遍。

在第 6 代 iPod Touch 型号上使用 10.0.2 (14A456) 进行测试 mkh22ll/a,我可以使用 Locate app for iOS 成功扫描信标并传输 iBeacon。这是用 Objective C 编写的,但使用与您展示的相同的 API。您可以在有问题的设备上尝试使用相同的应用,看看是否仍有问题。

在同一台设备上测试另一个用 Swift 3 编写的应用程序(该应用程序同时传输和接收 iBeacon 数据包),我已验证它成功接收并发送了 iBeacon 数据包。

最重要的是,iOS 10 上的 iBeacon 传输和检测在某些设备上运行良好。

我怀疑 iOS 10 的蓝牙问题只发生在某些具有不同蓝牙硬件芯片组的 iPhone 硬件型号(并且可能只发生在这些型号的某些特定设备上)。

一些可能有助于解决问题的事情:

  1. 关闭蓝牙并重新打开。
  2. 重新启动您的设备。 (蹩脚的建议,我知道。)
  3. 尝试 super 简单的操作,例如在“设置”中扫描附近的其他蓝牙设备,看看您是否可以看到其他设备,例如您的 Mac 或蓝牙扬声器。如果这个简单的蓝牙任务不起作用,iBeacon 就无法工作。
  4. 使用上述 Locate app 进行测试。这可能会消除编码问题。

请使用您的硬件设备更新问题。

关于ios - iBeacons 在 iOS 10.0.2 中损坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40051552/

相关文章:

ios - 如何按最近距离对对象数组(纬度,经度)进行排序?

ios - 使用 segue 将 CLLocation 传递到下一个 View

swift - 位置管理器不检测信标

android - 使用 Radius Networks Pro iBeacon SDK 的后台 BLE 触发器

ios - 接收具有相同uuid和不同专业,副修背景的iBeacon

ios - Appium1.13.0 似乎不支持 XCUITest Simulator 架构

android - 如何在 calabash-ios/calabash-android 中找到相关的 WebView 元素

ios - UITableViewCell 中的 mask 图像

ios - 在接收推送时获取位置

ios - 加速核心定位