#[repr(C)]pub struct IOBluetoothDeviceInquiry { /* private fields */ }IOBluetoothDeviceInquiry and objc2 only.Expand description
Object representing a device inquiry that finds Bluetooth devices in-range of the computer, and (optionally) retrieves name information for them.
You should only use this object if your application needs to know about in-range devices and cannot use the GUI provided by the IOBluetoothUI framework. It will not let you perform unlimited back-to-back inquiries, but will instead throttle the number of attempted inquiries if too many are attempted within a small window of time. Important Note: DO NOT perform remote name requests on devices from delegate methods or while this object is in use. If you wish to do your own remote name requests on devices, do them after you have stopped this object. If you do not heed this warning, you could potentially deadlock your process.
See also Apple’s documentation
Implementations§
Source§impl IOBluetoothDeviceInquiry
impl IOBluetoothDeviceInquiry
pub unsafe fn delegate(&self) -> Option<Retained<AnyObject>>
Sourcepub unsafe fn setDelegate(&self, delegate: Option<&AnyObject>)
pub unsafe fn setDelegate(&self, delegate: Option<&AnyObject>)
Setter for delegate.
Sourcepub unsafe fn inquiryWithDelegate(
delegate: Option<&AnyObject>,
) -> Option<Retained<Self>>
pub unsafe fn inquiryWithDelegate( delegate: Option<&AnyObject>, ) -> Option<Retained<Self>>
Class method to create an inquiry object.
Parameter delegate: A delegate object that wishes to receive messages from the inquiry object. Delegate methods are listed below, under IOBluetoothDeviceInquiryDelegate.
Returns: A pointer to the created IOBluetoothDeviceInquiry object.
The inquiry is NOT automatically started. You musts call -start on it to start the search for in-range devices.
Sourcepub unsafe fn initWithDelegate(
this: Allocated<Self>,
delegate: Option<&AnyObject>,
) -> Option<Retained<Self>>
pub unsafe fn initWithDelegate( this: Allocated<Self>, delegate: Option<&AnyObject>, ) -> Option<Retained<Self>>
Initializes an alloc’d inquiry object, and sets the delegate object, as if -setDelegate: were called on it.
Parameter delegate: A delegate object that wishes to receive messages from the inquiry object. Delegate methods are listed below, under IOBluetoothDeviceInquiryDelegate.
Returns: A pointer to the initialized IOBluetoothDeviceInquiry object.
Sourcepub unsafe fn start(&self) -> c_int
pub unsafe fn start(&self) -> c_int
Tells inquiry object to begin the inquiry and name updating process, if specified.
Returns: Returns kIOReturnSuccess if start was successful. Returns kIOReturnBusy if the object is already in process. May return other IOReturn values, as appropriate.
Calling start multiple times in rapid succession or back-to-back will probably not produce the intended results. Inquiries are throttled if they are called too quickly in succession.
Sourcepub unsafe fn stop(&self) -> c_int
pub unsafe fn stop(&self) -> c_int
Halts the inquiry object. Could either stop the search for new devices, or the updating of found device names.
Returns: Returns kIOReturnSuccess if the inquiry is successfully stopped. Returns kIOReturnNotPermitted if the inquiry object is already stopped. May return other IOReturn values, as appropriate.
Sourcepub unsafe fn inquiryLength(&self) -> u8
pub unsafe fn inquiryLength(&self) -> u8
Set the length of the inquiry that is performed each time -start is used on an inquiry object.
Parameter seconds: Number of seconds the inquiry will search for in-range devices before refreshing device names, if specified.
Returns: Number of seconds the search will be performed.
A default of 10 seconds is used, unless a different value is specified using this method. Note that if you have called -start again too quickly, your inquiry may actually take much longer than what length you specify, as inquiries are throttled in the system. Also note that if you have the inquiry object updating device names for you, the whole inquiry process could be much longer than the specified length, depending on the number of devices found and how responsive to name requests they are. If you -must- have a strict inquiry length, disable name updates. In other words, this “length” only refers to the actual device discovery portion of the whole inquiry process.
Sourcepub unsafe fn setInquiryLength(&self, inquiry_length: u8)
pub unsafe fn setInquiryLength(&self, inquiry_length: u8)
Setter for inquiryLength.
Sourcepub unsafe fn searchType(&self) -> IOBluetoothDeviceSearchTypes
Available on crate feature IOBluetoothUserLib only.
pub unsafe fn searchType(&self) -> IOBluetoothDeviceSearchTypes
IOBluetoothUserLib only.Set the devices that are found.
Parameter searchType: Bluetooth versions the search will discover.
A default of kIOBluetoothDeviceSearchClassic is used, unless a different value is specified using this method.
Sourcepub unsafe fn setSearchType(&self, search_type: IOBluetoothDeviceSearchTypes)
Available on crate feature IOBluetoothUserLib only.
pub unsafe fn setSearchType(&self, search_type: IOBluetoothDeviceSearchTypes)
IOBluetoothUserLib only.Setter for searchType.
Sourcepub unsafe fn updateNewDeviceNames(&self) -> bool
pub unsafe fn updateNewDeviceNames(&self) -> bool
Sets whether or not the inquiry object will retrieve the names of devices found during the search.
Parameter inValue: Pass TRUE if names are to be updated, otherwise pass FALSE.
The default value for the inquiry object is TRUE, unless this method is used to change it.
Sourcepub unsafe fn setUpdateNewDeviceNames(&self, update_new_device_names: bool)
pub unsafe fn setUpdateNewDeviceNames(&self, update_new_device_names: bool)
Setter for updateNewDeviceNames.
Sourcepub unsafe fn foundDevices(&self) -> Option<Retained<NSArray>>
Available on crate feature objc2-foundation only.
pub unsafe fn foundDevices(&self) -> Option<Retained<NSArray>>
objc2-foundation only.Returns found IOBluetoothDevice objects as an array.
Returns: Returns an NSArray of IOBluetoothDevice objects.
Will not return nil. If there are no devices found, returns an array with length of 0.
Sourcepub unsafe fn clearFoundDevices(&self)
pub unsafe fn clearFoundDevices(&self)
Removes all found devices from the inquiry object.
Sourcepub unsafe fn setSearchCriteria_majorDeviceClass_minorDeviceClass(
&self,
in_service_class_major: BluetoothServiceClassMajor,
in_major_device_class: BluetoothDeviceClassMajor,
in_minor_device_class: BluetoothDeviceClassMinor,
)
Available on crate feature Bluetooth only.
pub unsafe fn setSearchCriteria_majorDeviceClass_minorDeviceClass( &self, in_service_class_major: BluetoothServiceClassMajor, in_major_device_class: BluetoothDeviceClassMajor, in_minor_device_class: BluetoothDeviceClassMinor, )
Bluetooth only.Use this method to set the criteria for the device search.
Parameter inServiceClassMajor: Set the major service class for found devices. Set to kBluetoothServiceClassMajorAny for all devices. See BluetoothAssignedNumbers.h for possible values.
Parameter inMajorDeviceClass: Set the major device class for found devices. Set to kBluetoothDeviceClassMajorAny for all devices. See BluetoothAssignedNumbers.h for possible values.
Parameter inMinorDeviceClass: Set the minor device class for found devices. Set to kBluetoothDeviceClassMinorAny for all devices. See BluetoothAssignedNumbers.h for possible values.
The default inquiry object will search for all types of devices. If you wish to find only keyboards, for example, you might use this method like this:
[myInquiryObject setSearchCriteria:kBluetoothServiceClassMajorAny majorDeviceClass:kBluetoothDeviceClassMajorPeripheral minorDeviceClass:kBluetoothDeviceClassMinorPeripheral1Keyboard];
However, we recommend only using this if you are certain of the device class you are looking for, as some devices may report a different/unexpected device class, and the search may miss the device you are interested in.
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init/new methods).
§Example
Check that an instance of NSObject has the precise class NSObject.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load instead.Use Ivar::load instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T.
See Ivar::load_ptr for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T.
This is the reference-variant. Use Retained::downcast if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString to a NSMutableString,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass: for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject.
§Panics
This works internally by calling isKindOfClass:. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject and
NSProxy implement this method.
§Examples
Cast an NSString back and forth from NSObject.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();Try (and fail) to cast an NSObject to an NSString.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}Trait Implementations§
Source§impl AsRef<AnyObject> for IOBluetoothDeviceInquiry
impl AsRef<AnyObject> for IOBluetoothDeviceInquiry
Source§impl AsRef<NSObject> for IOBluetoothDeviceInquiry
impl AsRef<NSObject> for IOBluetoothDeviceInquiry
Source§impl Borrow<AnyObject> for IOBluetoothDeviceInquiry
impl Borrow<AnyObject> for IOBluetoothDeviceInquiry
Source§impl Borrow<NSObject> for IOBluetoothDeviceInquiry
impl Borrow<NSObject> for IOBluetoothDeviceInquiry
Source§impl ClassType for IOBluetoothDeviceInquiry
impl ClassType for IOBluetoothDeviceInquiry
Source§const NAME: &'static str = "IOBluetoothDeviceInquiry"
const NAME: &'static str = "IOBluetoothDeviceInquiry"
Source§type ThreadKind = <<IOBluetoothDeviceInquiry as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<IOBluetoothDeviceInquiry as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for IOBluetoothDeviceInquiry
impl Debug for IOBluetoothDeviceInquiry
Source§impl Deref for IOBluetoothDeviceInquiry
impl Deref for IOBluetoothDeviceInquiry
Source§impl Hash for IOBluetoothDeviceInquiry
impl Hash for IOBluetoothDeviceInquiry
Source§impl Message for IOBluetoothDeviceInquiry
impl Message for IOBluetoothDeviceInquiry
Source§impl NSObjectProtocol for IOBluetoothDeviceInquiry
impl NSObjectProtocol for IOBluetoothDeviceInquiry
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass directly, or cast your objects with AnyObject::downcast_ref