objective-c版
main.m
#import <Foundation/Foundation.h>
#import <IOBluetooth/objc/IOBluetoothDevice.h>
int main(int argc, const char * argv[])
{
NSLog(@"start");
NSString *addrStr = @"xx:xx:xx:xx:xx:xx"; // bluetooth deviceのMAC Address
IOBluetoothDevice *device = [IOBluetoothDevice deviceWithAddressString:addrStr];
// タイムアウト3秒
[device openConnection:nil withPageTimeout:3000 authenticationRequired:false];
if ([device isConnected]) {
NSLog(@"connected !!!");
} else {
NSLog(@"not connected");
}
[device closeConnection];
return 0;
}
macruby版
macruby-sample.rb
#! /usr/bin/env macruby
framework 'Foundation'
framework 'IOBluetooth'
device = IOBluetoothDevice.deviceWithAddressString "xx:xx:xx:xx:xx:xx"
device.openConnection(nil, withPageTimeout: 3000, authenticationRequired: false)
if device.isConnected
puts 'connected!!!'
else
puts 'not connected.'
end
device.closeConnection