繁体   English   中英

iBeacons在iOS 10.0.2中被破坏了吗?

[英]iBeacons Broken in iOS 10.0.2?

到目前为止,大家如何在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上运行 - 似乎根本没有做广告。

我已经将代码缩减为一个非常简单的助手类和一个我认为应该充分展示问题的视图控制器。 请注意,故事板只有一个按钮连接到启动/停止iBeacon广告。

我在iPhone 5和iOS 7的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上报告了蓝牙问题,但问题并不普遍。

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

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

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

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

一些可能有助于排除故障的事情:

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

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

我还尝试使用iPhone 7(A1778)和iPhone 6S(A1688)进行iBeacon Region监控。 我还体验到,在iPhone 7上永远不会执行didEnterRegiondidExitRegion 。原因可能就是苹果放弃了iPhone 7上的iBeacon微位置。

根据技术规格,iPhone 7不再列出“iBeacon微定位”。以下是iPhone 7的技术规格: https//support.apple.com/kb/SP743? locale = en_US以下是iPhone 6S: https//support.apple.com/kb/SP726? locale = en_US

我尝试重新启动,实际上它有助于让应用程序在前台运行时工作。 后台的区域监控根本不起作用。 如果您在应用程序处于后台后回到前台,它也不起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM