PyObjC Framework IOBluetooth
PyObjC Framework IOBluetooth is a Python binding for the IOBluetooth framework on macOS. It enables Python applications to interact with Bluetooth devices and services through Objective-C APIs. The library is currently at version 12.1 and typically releases new versions in conjunction with macOS SDK updates and PyObjC core developments, ensuring compatibility with the latest Apple technologies.
Warnings
- breaking PyObjC 12.0 dropped support for Python 3.9. Users on Python 3.9 must use an older version of pyobjc-framework-iobluetooth (or the full pyobjc package).
- breaking PyObjC 11.0 dropped support for Python 3.8. Users on Python 3.8 must use an older version of pyobjc-framework-iobluetooth (or the full pyobjc package).
- breaking Version 11.1 changed how initializer methods (methods in the 'init' family) handle references, aligning with `clang`'s Automatic Reference Counting (ARC) documentation. This means `init` methods now steal a reference to `self` and return a new one, which can alter object lifecycle management.
- gotcha PyObjC is a macOS-specific bridge. `pyobjc-framework-iobluetooth` will only function on macOS and cannot be used on other operating systems.
- gotcha Changes in `__init__` and `__new__` behavior in versions 10.3 and 10.3.1 can cause issues. While `__init__` was initially disabled when PyObjC provided `__new__` (v10.3), it was re-enabled for user-implemented `__new__` (v10.3.1). This interaction can be tricky for custom class creation patterns.
- gotcha Installing PyObjC and its framework bindings may require Apple's Xcode Command Line Tools to be installed, especially for certain Python versions or environments.
Install
-
pip install pyobjc-framework-iobluetooth
Imports
- IOBluetooth
import IOBluetooth
- objc
import objc
- NSObject, NSBundle
from Foundation import NSObject, NSBundle
Quickstart
import objc
from Foundation import NSBundle
import IOBluetooth
# Verify that the IOBluetooth framework is loaded and accessible
print(f"IOBluetooth module loaded: {IOBluetooth is not None}")
if IOBluetooth is not None:
# Access a common class from the IOBluetooth framework, e.g., IOBluetoothDevice
# and try to get its bundle identifier to confirm functionality.
device_class = IOBluetooth.IOBluetoothDevice
if device_class:
print(f"Successfully accessed IOBluetoothDevice class: {device_class}")
# Get the bundle for the class to show a more concrete interaction
bundle = NSBundle.bundleForClass_(device_class)
if bundle:
print(f"IOBluetooth bundle identifier: {bundle.bundleIdentifier()}")
else:
print("Could not retrieve bundle for IOBluetoothDevice class.")
else:
print("Failed to access IOBluetoothDevice class.")