一个Xcode初学者的问题:
这是我第一次使用Xcode 4.6.3.
我正在尝试编写一个非常简单的控制台程序,搜索配对的BT设备并将它们打印到NSLog.
它构建时出现以下错误:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_IOBluetoothDevice", referenced from:
objc-class-ref in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
我疯狂地搜索.常见问题应该是对文件的引用,其中只导入头文件,链接器不会找到实现(*.m-file).然而,IOBluetooth库是一个像Foundation Framework一样的标准框架.
我在上述陈述中缺少什么?
我也尝试过为32位机器构建它(再次构建失败).这显然是一个链接器错误,但我不知道它与它有什么关系,除了在x86和x64架构上找到IOBluetoothDevice的实现存在问题,而头文件来自标准包含的Framework,称为IOBluetooth?
为了您的信息,我的主要代码"main.m"是:
#import <Foundation/Foundation.h>
#import <IOBluetooth/objc/IOBluetoothDevice.h> // Note the import for bluetooth
#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h> // Note the import for bluetooth
int main(int argc, const char * argv[])
{
@autoreleasepool {
IOBluetoothDevice *currentDevice;
NSArray *devices = [ IOBluetoothDevice pairedDevices];
for (id …Run Code Online (Sandbox Code Playgroud) 我试图通过编程方式获取iPhone/iPod蓝牙的状态,无论是开启还是关闭.是否可以使用某些Apple API或第三方API.
我试图IOBluetooth framework在OS X 10.8.2上使用连接蓝牙手机模拟计算机作为免提设备.我可以成功与手机建立连接,手机可以将连接识别为连接到手机的HandsFree.但是当我尝试使用手机拨打电话并想要将音频发送到mac(通过选择来源作为免提)时,音频永远不会到达计算机.
此时蓝牙框架尝试打开SCO Audio connection设备,但连接建立从未成功,我得到0x0DscoConnectionOpened状态的错误代码状态代码.
我正在使用IOBluetoothAddSCOAudioDevice功能将SCO音频设备连接到蓝牙设备,它总是成功的.
//btDevice is paired
res=IOBluetoothAddSCOAudioDevice((IOBluetoothDeviceRef) btDevice,NULL);
if(res != kIOReturnSuccess)
{
self.error.title = [NSString stringWithFormat:
@"Could not attach the Audio device. Try paring device again"];
}
Run Code Online (Sandbox Code Playgroud)
控制台日志说
24/11/2012 4:02:13.000 PM kernel [0]:[SendHCIRequestFormatted] ### ERROR:[0x0428](设置同步连接) - 发送请求失败(错误= 0x000D(kBluetoothHCIErrorHostRejectedLimitedResources))
24/11/2012 4:02:13.000 PM内核[0]:REQUIRE_NO_ERR失败:0xd - 文件:/SourceCache/IOBluetoothFamily_kexts/IOBluetoothFamily-4090.4.33/Core/Family/Drivers/IOBluetoothSCOAudioDriver/IOBluetoothSCOAudioDevice.cpp:872
虽然控制台日志说有限的资源,但我尝试了多个电池充满电池.
我对此感到难过,只是想我是否需要做任何特殊或不同的事情?
在此先感谢您的帮助.
我正在尝试使用我的Mac mini中的蓝牙开发应用程序.然而,在搜索全网后,我能找到的只是Apple的"蓝牙设备访问指南",而不是单个示例程序!
任何人都可以建议任何示例代码吗?
我想在我的程序中做什么:
我想通过PAN配置文件以编程方式将我的iPhone与我的Mac配对,然后以两种方式发送数据(流).我手动配对它,我成功地传输了数据.我只是想以编程方式做到这一点!
我正在研究一个需要我的Mac将一些数据发送到我的iOS设备的想法.我知道CoreBluetooth框架不适用于Mac OS,只适用于iOS,所以有什么方法可以让我的Mac构成一个外围设备?
我做了一些谷歌搜索 - 没有得到一个直接的答案:(
该CBCentralManagerScanOptionSolicitedServiceUUIDsKey文档指出,在CoreBluetooth中扫描设备时可以使用该选项
指定此扫描选项会导致中央管理器也扫描外围设备,请求获取阵列中包含的任何服务.
这个选项的目的是什么?什么是"征求服务"?在services数组中指定服务UUID有何不同?
我正在寻找一种方法来以编程方式列出我的设备找到的任何附近的蓝牙设备(可发现).我无法在Swift 3.0中找到有关执行此调用的任何信息或教程.这篇QA文章讨论了使用Swift 1.0查找这些设备并使用Xcode 6构建,而不是最新版本8.
我尽力尝试将我的代码从1.0开始编写3.0语法,但在运行以下代码时,Playground中没有返回任何内容:
import Cocoa
import IOBluetooth
import PlaygroundSupport
class BlueDelegate : IOBluetoothDeviceInquiryDelegate {
func deviceInquiryComplete(_ sender: IOBluetoothDeviceInquiry, error: IOReturn, aborted: Bool) {
aborted
print("called")
let devices = sender.foundDevices()
for device : Any? in devices! {
if let thingy = device as? IOBluetoothDevice {
thingy.getAddress()
}
}
}
}
var delegate = BlueDelegate()
var inquiry = IOBluetoothDeviceInquiry(delegate: delegate)
inquiry?.start()
PlaygroundPage.current.needsIndefiniteExecution = true
Run Code Online (Sandbox Code Playgroud) 我无法理解API来设置在OSX上运行的l2cap(或RFCOMM)客户端/服务器,就像我在Linux上使用BlueZ一样.
在Linux上,我只是打开一个套接字,绑定,监听然后接受服务器,&socket,绑定,连接客户端(w /绑定接收我想要使用的设备的BT地址).此外,没有完成配对.
我无法弄清楚如何配置我的应用程序以开始侦听特定设备上的连接(或者如果OSX一次只支持1个BT适配器,那么如何监听任何传入连接).
我也无法弄清楚如何配置我的应用程序使用特定设备发送到一个BT设备(如果OSX一次只支持1个,这是无关紧要的).
另外,OSX堆栈是否需要在2个设备通过l2cap之前发生配对?
任何语言示例都会受到赞赏,尽管C/C++会更受欢迎.
谢谢
我已经IOBluetoothDevice在我的Mac/Cocoa应用程序中配对,并希望以编程方式"取消配对".也就是说,我想从"系统偏好设置"的"蓝牙"部分的左侧窗格中删除该设备.
我已经看过了[IOBluetoothDevice removeFromFavorites],但是只删除了设备"收藏夹"属性旁边的心脏图标 - 设备仍然列在左侧窗格中.
这可能通过Cocoa吗?

在上图中,我想以编程方式从左侧窗格中删除"Apple Mighty Mouse".
我在Xcode 6游乐场中有以下代码:
import Cocoa
import IOBluetooth
class BlueDelegate : IOBluetoothDeviceInquiryDelegate {
func deviceInquiryComplete(sender: IOBluetoothDeviceInquiry, error: IOReturn, aborted: Bool) {
aborted
var devices = sender.foundDevices()
for device : AnyObject in devices {
if let thingy = device as? IOBluetoothDevice {
thingy.getAddress()
}
}
}
}
var inquiry = IOBluetoothDeviceInquiry(delegate: BlueDelegate())
inquiry.start()
Run Code Online (Sandbox Code Playgroud)
我刚开始使用OSX下的蓝牙,而我目前想要的只是范围内的设备列表.
它似乎根本没有调用我的委托方法.
我是OSX开发和Swift的新手,所以请保持温和.:)
iobluetooth ×10
bluetooth ×7
macos ×7
cocoa ×4
ios ×4
objective-c ×4
swift ×2
audio ×1
c ×1
cbperipheral ×1
iphone ×1
xcode ×1