简体   繁体   English

iBeacons在iOS 10.0.2中被破坏了吗?

[英]iBeacons Broken in iOS 10.0.2?

How's everyone doing with iBeacons on iOS 10.0.2 so far? 到目前为止,大家如何在iOS 10.0.2上使用iBeacons? I hope better than me! 我希望比我好! :-) :-)

Update: Hardware used for testing was two iPhones. 更新:用于测试的硬件是两个iPhone。 The iPhone 5S(A1533) and the iPhone 7(A1778) iPhone 5S(A1533)和iPhone 7(A1778)

A swift 2.x version of the code below could be used on an iPhone to advertise a simple iBeacon on iOS versions 9.x; 以下代码的swift 2.x版本可以在iPhone上用于在iOS版本9.x上宣传简单的iBeacon; today, the same code - updated for swift 3 and running on iOS 10.0.2 - doesn't appear to advertise at all. 今天,相同的代码 - 更新为swift 3并在iOS 10.0.2上运行 - 似乎根本没有做广告。

I've cut code down to a very simple helper class and a viewcontroller that I think should adequately demonstrate the problem. 我已经将代码缩减为一个非常简单的助手类和一个我认为应该充分展示问题的视图控制器。 Note that the storyboard has just one button connected to start/stop iBeacon advertising. 请注意,故事板只有一个按钮连接到启动/停止iBeacon广告。

I've run the app on an iPhone 5 and an iPhone 7 with iOS 10.0.2. 我在iPhone 5和iOS 7的iPhone 7上运行应用程序。 To test I created a custom scanner (sniffing for the specific proximity UUID,) and when that didn't work I tried more generic iBeacon detecting apps, like Estimote and LightBlue. 为了测试我创建了一个自定义扫描程序(嗅探特定的邻近UUID),当这不起作用时,我尝试了更多通用的iBeacon检测应用程序,如Estimote和LightBlue。

Sigh - nothing sees the iBeacon. 叹息 - 没有看到iBeacon。

Thoughts? 思考? The developer forums at Apple mention problems reported with iBeacons in 10.x, but none as simple as this as far as I can tell. Apple的开发者论坛提到了10.x中iBeacons报告的问题,但据我所知,没有一个简单。

Thanks a bunch... 谢谢你......

- - - 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 - - - - -

(Apologies for any code format mistakes.) (对任何代码格式错误表示道歉。)

Lots of people report trouble with bluetooth on iOS 10, but the trouble isn't universal. 很多人都在iOS 10上报告了蓝牙问题,但问题并不普遍。

Testing with 10.0.2 (14A456) on an iPod Touch 6th Generation model mkh22ll/a, I can successfully scan for beacons and transmit iBeacon using the Locate app for iOS . 在iPod Touch第6代型号mkh22ll / a上使用10.0.2(14A456)进行测试,我可以使用适用于iOSLocate app成功扫描信标并传输iBeacon。 This is written in Objective C, but uses the same APIs as you are showing. 这是用Objective C编写的,但使用与您显示的API相同的API。 You might try this same app on the problematic device and see if you still have trouble. 您可以在有问题的设备上尝试使用相同的应用程序,看看您是否还有问题。

Testing another app that is written in Swift 3 on the same device (the app both transmits and receives iBeacon packets), I have verified that it successfully receives iBeacon packets and sends them, too. 测试在同一设备上使用Swift 3编写的另一个应用程序(应用程序都发送和接收iBeacon数据包),我已经验证它成功接收了iBeacon数据包并发送它们。

The bottom line is that iBeacon transmission and detection on iOS 10 works fine on some devices. 最重要的是, iOS 10上的iBeacon传输和检测在某些设备上运行良好。

I suspect that bluetooth problems with iOS 10 only happen with certain iPhone hardware models (and perhaps only on certain specific devices of these models) that have somewhat different bluetooth hardware chipsets. 我怀疑iOS 10的蓝牙问题只发生在具有某些不同蓝牙硬件芯片组的某些iPhone硬件模型上(并且可能仅在这些模型的某些特定设备上)。

A few things that may help troubleshoot: 一些可能有助于排除故障的事情:

  1. Turn bluetooth off and back on. 关闭蓝牙并重新打开。
  2. Reboot your device. 重启设备。 (Lame suggestion, I know.) (拉姆的建议,我知道。)
  3. Try super simple operations like scanning for other nearby bluetooth devices in Settings, and see if you can see other devices like your Mac or bluetooth speakers. 尝试超级简单的操作,例如在“设置”中扫描其他附近的蓝牙设备,看看是否可以看到其他设备,如Mac或蓝牙扬声器。 If this simple bluetooth task doesn't work, there is no way iBeacon will work. 如果这个简单的蓝牙任务不起作用,iBeacon就无法工作。
  4. Test with the Locate app described above. 使用上述定位应用程序进行测试。 This may eliminate a coding issue. 这可以消除编码问题。

Please do update the question with your hardware device. 请使用您的硬件设备更新问题。

I also tried iBeacon Region monitoring with the iPhone 7 (A1778) and on the iPhone 6S (A1688). 我还尝试使用iPhone 7(A1778)和iPhone 6S(A1688)进行iBeacon Region监控。 I also experience that didEnterRegion and didExitRegion is never executed on the iPhone 7. The reason for that maybe that Apple dropped iBeacon micro location on the iPhone 7. 我还体验到,在iPhone 7上永远不会执行didEnterRegiondidExitRegion 。原因可能就是苹果放弃了iPhone 7上的iBeacon微位置。

According to the technical specs "iBeacon microlocation" is no longer listed for the iPhone 7. Here are the tech specs of the iPhone 7: https://support.apple.com/kb/SP743?locale=en_US Here are the ones of the iPhone 6S: https://support.apple.com/kb/SP726?locale=en_US 根据技术规格,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

I've tried rebooting and actually it helps to let it work while the app is running in the foreground. 我尝试重新启动,实际上它有助于让应用程序在前台运行时工作。 Region monitoring in the background is not working at all. 后台的区域监控根本不起作用。 It also does not work if you come back to foreground after the app has been in the background. 如果您在应用程序处于后台后回到前台,它也不起作用。

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

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