Created
October 20, 2009 10:07
-
-
Save oz/214140 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple bluetooth scan with IOBluetooth (macruby) | |
framework 'appkit' | |
framework 'IOBluetooth' | |
# IOBluetoothInquiryDelegate | |
class EventHandler | |
def deviceInquiryStarted(sender) | |
puts "Searching for devices..." | |
end | |
def deviceInquiryComplete(sender, error:error, aborted:aborted) | |
puts "User abort!" if aborted | |
puts "Scanning stopped, bye." | |
exit | |
end | |
def deviceInquiryDeviceFound(sender, device:device) | |
puts "Device found: #{device} (name: #{device.nameOrAddress})" | |
end | |
def deviceInquiryDeviceNameUpdated(sender, device:device, devicesRemaining:remaining) | |
puts "Update name of device #{device}: '#{device.nameOrAddress}'" | |
end | |
def deviceInquiryUpdatingDeviceNamesStarted(sender, devicesRemaining:remaining) | |
puts "Updating names of: #{remaining}" | |
sender.stop if remaining == 0 | |
end | |
end | |
# NSApplication | |
class AppDelegate | |
def applicationDidFinishLaunching(notification) | |
event_handler = EventHandler.new | |
inquiry = IOBluetoothDeviceInquiry.new | |
inquiry.setUpdateNewDeviceNames(true) | |
inquiry.setDelegate(event_handler) | |
inquiry.start | |
end | |
end | |
# let's run. :) | |
app = NSApplication.sharedApplication | |
app.delegate = AppDelegate.new | |
app.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment