gpt4 book ai didi

ios - 如何在 OSX 应用程序中使用核心蓝牙?

转载 作者:行者123 更新时间:2023-11-28 13:13:14 25 4
gpt4 key购买 nike

我尝试在我目前正在开发的 OS X 应用程序中使用核心蓝牙框架,这实际上会将您的 Mac 连接到您的 iphone 以通过蓝牙 LE 执行不同的操作。

问题是,当我简单地初始化 CBCentralManager 和它的委托(delegate)方法时,我得到了一个奇怪的错误:

    Undefined symbols for architecture x86_64:
"_CBAdvertisementDataLocalNameKey", referenced from:
__TFC5test311AppDelegate14centralManagerfS0_FTGSQCSo16CBCentralManager_21didDiscoverPeripheralGSQCSo12CBPeripheral_17advertisementDataGSQGVSs10DictionaryCSo8NSObjectPSs9AnyObject___4RSSIGSQCSo8NSNumber__T_ in AppDelegate.o
"_OBJC_CLASS_$_CBCentralManager", referenced from:
__TMaCSo16CBCentralManager in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

下面是我的代码:

import Cocoa
import CoreBluetooth

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, CBCentralManagerDelegate {

@IBOutlet weak var window: NSWindow!
var centralManager: CBCentralManager!

func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) {

var localName: String = advertisementData[CBAdvertisementDataLocalNameKey] as String

if (countElements(localName) > 0) {
println("Found Mac: \(localName)")
self.centralManager.stopScan()
} else {
println("Not Found")
}
}
func centralManager(central: CBCentralManager!, didConnectPeripheral peripheral: CBPeripheral!) {
println("1")
}

func centralManager(central: CBCentralManager!, didDisconnectPeripheral peripheral: CBPeripheral!, error: NSError!) {
println("2")
}

func centralManagerDidUpdateState(central: CBCentralManager!) {
switch (central.state) {
case .PoweredOff:
println("Powered Off")
case .PoweredOn:
println("Powered On")
self.centralManager.scanForPeripheralsWithServices(nil, options: nil)
case .Unauthorized:
println("Unauthorized")
case .Unknown:
println("Unknown")
case .Unsupported:
println("Unsupported")
default:
println("Default")
}
}

func applicationDidFinishLaunching(aNotification: NSNotification) {
self.centralManager = CBCentralManager(delegate: nil, queue: nil)
// Insert code here to initialize your application
}

func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
}

我不确定为什么会出现该错误,或​​者我做错了什么

最佳答案

我在 MacOS 10.13 上遇到了同样的错误,

  • 我首先将Privacy - Bluetooth Peripheral Usage Description 添加到 info.plist。
  • 接下来我发现在项目设置 -> 目标(你的应用程序) -> 功能 -> 应用程序沙盒 -> 蓝牙中必须检查。

Check Bluetooth

关于ios - 如何在 OSX 应用程序中使用核心蓝牙?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30427368/

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