JP.*_*JP. 7 cocoa bluetooth objective-c
我正在尝试编写一个非常简单的终端应用程序,它将定期扫描蓝牙设备并显示范围内每个蓝牙设备的蓝牙网络地址(十六进制数字).我的目标平台是Mac OS X,所以我认为这将涉及Objective-C.我没有Objective-C的任何经验(虽然我有C的所有基础知识),但这看起来应该非常简单.
我在哪里可以找到快速本地列出蓝牙设备的文档和示例代码(或教程,或者过去曾经使用过的代码)?
使用带有Objective-C的蓝牙可以通过IOBluetooth框架实现.
一些用于基本操作的有用类的示例是:
IOBluetoothDevice
[IOBluetoothDevice pairedDevices]
返回配对设备的NSArrayIOBluetoothDeviceInquiry
IOBluetoothHostController
powerState
物业可以告诉您自己的蓝牙是打开还是关闭以下是一些示例代码,IOBluetoothDeviceInquiry
用于获取范围内每个蓝牙设备的地址.开始查询过程,例如:
IOBluetoothDeviceInquiry *inquirer = [IOBluetoothDeviceInquiry inquiryWithDelegate:self];
// Configure further here if necessary
[inquirer start];
Run Code Online (Sandbox Code Playgroud)
现在,您可以使用以下IOBluetoothDeviceInquiryDelegate
方法获取找到的设备的地址:
#pragma mark - IOBluetoothDeviceInquiryDelegate Methods
- (void) deviceInquiryComplete:(IOBluetoothDeviceInquiry *)sender error:(IOReturn)error aborted:(BOOL)aborted {
NSArray *devices = [sender foundDevices];
for (IOBluetoothDevice *device in devices) {
const BluetoothDeviceAddress *address = [device getAddress];
// Do something with address
}
[sender performSelector:@selector(start) withObject:nil afterDelay:7];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11877 次 |
最近记录: |