gpt4 book ai didi

ios - CoreBluetooth 广告但无法从其他设备看到

转载 作者:行者123 更新时间:2023-11-29 00:32:00 27 4
gpt4 key购买 nike

我试图将 iOS iPhone 设置为蓝牙外围设备,这样我就可以从另一个 iDevice 蓝牙设备看到它并发送信息。

我认为我在为自己做广告,但我无法从其他 iPhone、iPad 或 Mac 的任何地方看到它。控制台输出表明它是广告?我是否错过了一些明显的东西,(我环顾四周,谷歌搜索和这里)但没有运气。

控制台:

self.peripheralManager powered on.
Service Added
peripheralManagerDidStartAdvertising(_:error:)
Advertising

代码:

import UIKit
import CoreBluetooth
class ViewController: UIViewController,CBPeripheralManagerDelegate {
var peripheralManager:CBPeripheralManager!
var transferCharacteristic: CBMutableCharacteristic?
let MyP_Service_UUID = CBUUID(string: "1B981746-2064-4F68-BBB8-69A185314FC6")
let MyP_Characteristics_UUID = CBUUID(string: "4271CEC1-652D-489B-8484-7C3550C6075E")
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.peripheralManager = CBPeripheralManager(delegate: self, queue: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
// Don't keep it going while we're not showing.
peripheralManager.stopAdvertising()
}
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
if (peripheral.state != .poweredOn) {
return
}
print("self.peripheralManager powered on.")
// ... so build our service.
let myCharacteristic = CBMutableCharacteristic(type: MyP_Characteristics_UUID, properties: [.notify], value: nil, permissions: .readable)
let myService = CBMutableService(type: MyP_Service_UUID, primary: true)
myService.characteristics?.append(myCharacteristic)
peripheralManager.add(myService)
peripheralManager.startAdvertising([ CBAdvertisementDataServiceUUIDsKey: [MyP_Service_UUID], CBAdvertisementDataLocalNameKey : "MyP"])
}

func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?) {
print(error ?? "Service Added")
}
func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) {
print(#function)
print(error ?? "Advertising")
}
func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didSubscribeTo characteristic: CBCharacteristic) {
print(#function)
}
func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didUnsubscribeFrom characteristic: CBCharacteristic) {
print(#function)
}
func peripheralManagerIsReady(toUpdateSubscribers peripheral: CBPeripheralManager) {
print(#function)
}

}

最佳答案

为了获得更好的支持,我们需要在 BLE Central 端查看您的代码。您是否在扫描设备上扫描相同的服务 UUID?

顺便说一句,根据您的用例,您可能想要检查可以为您处理所有蓝牙交互的其他 SDK。例如:MultipeerConnectivity、p2pkit、附近的谷歌。

免责声明:我在开发 p2pkit 的团队工作

关于ios - CoreBluetooth 广告但无法从其他设备看到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41505087/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com