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