#[repr(C)]pub struct CBCentralManager { /* private fields */ }
CBCentralManager
and CBManager
only.Expand description
Entry point to the central role. Commands should only be issued when its state is
CBCentralManagerStatePoweredOn
.
See also Apple’s documentation
Implementations§
Source§impl CBCentralManager
impl CBCentralManager
Sourcepub unsafe fn delegate(
&self,
) -> Option<Retained<ProtocolObject<dyn CBCentralManagerDelegate>>>
pub unsafe fn delegate( &self, ) -> Option<Retained<ProtocolObject<dyn CBCentralManagerDelegate>>>
The delegate object that will receive central events.
Sourcepub unsafe fn setDelegate(
&self,
delegate: Option<&ProtocolObject<dyn CBCentralManagerDelegate>>,
)
pub unsafe fn setDelegate( &self, delegate: Option<&ProtocolObject<dyn CBCentralManagerDelegate>>, )
This is a weak property.
Setter for delegate
.
Sourcepub unsafe fn isScanning(&self) -> bool
pub unsafe fn isScanning(&self) -> bool
Whether or not the central is currently scanning.
Sourcepub unsafe fn supportsFeatures(features: CBCentralManagerFeature) -> bool
pub unsafe fn supportsFeatures(features: CBCentralManagerFeature) -> bool
Parameter features
: One or more features you would like to check if supported.
Returns a boolean value representing the support for the provided features.
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
Sourcepub unsafe fn initWithDelegate_queue(
this: Allocated<Self>,
delegate: Option<&ProtocolObject<dyn CBCentralManagerDelegate>>,
queue: Option<&DispatchQueue>,
) -> Retained<Self>
Available on crate feature dispatch2
only.
pub unsafe fn initWithDelegate_queue( this: Allocated<Self>, delegate: Option<&ProtocolObject<dyn CBCentralManagerDelegate>>, queue: Option<&DispatchQueue>, ) -> Retained<Self>
dispatch2
only.Parameter delegate
: The delegate that will receive central role events.
Parameter queue
: The dispatch queue on which the events will be dispatched.
The initialization call. The events of the central role will be dispatched on the provided queue. If nil , the main queue will be used.
Sourcepub unsafe fn initWithDelegate_queue_options(
this: Allocated<Self>,
delegate: Option<&ProtocolObject<dyn CBCentralManagerDelegate>>,
queue: Option<&DispatchQueue>,
options: Option<&NSDictionary<NSString, AnyObject>>,
) -> Retained<Self>
Available on crate feature dispatch2
only.
pub unsafe fn initWithDelegate_queue_options( this: Allocated<Self>, delegate: Option<&ProtocolObject<dyn CBCentralManagerDelegate>>, queue: Option<&DispatchQueue>, options: Option<&NSDictionary<NSString, AnyObject>>, ) -> Retained<Self>
dispatch2
only.Parameter delegate
: The delegate that will receive central role events.
Parameter queue
: The dispatch queue on which the events will be dispatched.
Parameter options
: An optional dictionary specifying options for the manager.
The initialization call. The events of the central role will be dispatched on the provided queue. If nil , the main queue will be used.
See also: CBCentralManagerOptionShowPowerAlertKey
See also: CBCentralManagerOptionRestoreIdentifierKey
Sourcepub unsafe fn retrievePeripheralsWithIdentifiers(
&self,
identifiers: &NSArray<NSUUID>,
) -> Retained<NSArray<CBPeripheral>>
Available on crate features CBPeer
and CBPeripheral
only.
pub unsafe fn retrievePeripheralsWithIdentifiers( &self, identifiers: &NSArray<NSUUID>, ) -> Retained<NSArray<CBPeripheral>>
CBPeer
and CBPeripheral
only.Parameter identifiers
: A list of
NSUUID
objects.
Attempts to retrieve the
CBPeripheral
object(s) with the corresponding
identifiers
.
Returns: A list of
CBPeripheral
objects.
Sourcepub unsafe fn retrieveConnectedPeripheralsWithServices(
&self,
service_uui_ds: &NSArray<CBUUID>,
) -> Retained<NSArray<CBPeripheral>>
Available on crate features CBPeer
and CBPeripheral
and CBUUID
only.
pub unsafe fn retrieveConnectedPeripheralsWithServices( &self, service_uui_ds: &NSArray<CBUUID>, ) -> Retained<NSArray<CBPeripheral>>
CBPeer
and CBPeripheral
and CBUUID
only.Retrieves all peripherals that are connected to the system and implement any of the services listed in serviceUUIDs . Note that this set can include peripherals which were connected by other applications, which will need to be connected locally via {
connectPeripheral:options:} before they can be used.
@return A list of <code>CBPeripheral</code> objects.
Sourcepub unsafe fn scanForPeripheralsWithServices_options(
&self,
service_uui_ds: Option<&NSArray<CBUUID>>,
options: Option<&NSDictionary<NSString, AnyObject>>,
)
Available on crate feature CBUUID
only.
pub unsafe fn scanForPeripheralsWithServices_options( &self, service_uui_ds: Option<&NSArray<CBUUID>>, options: Option<&NSDictionary<NSString, AnyObject>>, )
CBUUID
only.Parameter serviceUUIDs
: A list of
CBUUID
objects representing the service(s) to scan for.
Parameter options
: An optional dictionary specifying options for the scan.
Starts scanning for peripherals that are advertising any of the services listed in
serviceUUIDs
. Although strongly discouraged,
if
serviceUUIDs
is
nil
all discovered peripherals will be returned. If the central is already scanning with different
serviceUUIDs
or
options
, the provided parameters will replace them.
Applications that have specified the
bluetooth-central
background mode are allowed to scan while backgrounded, with two
caveats: the scan must specify one or more service types in
serviceUUIDs
, and the
CBCentralManagerScanOptionAllowDuplicatesKey
scan option will be ignored.
See: centralManager:didDiscoverPeripheral:advertisementData:RSSI:
See also: CBCentralManagerScanOptionAllowDuplicatesKey
See also: CBCentralManagerScanOptionSolicitedServiceUUIDsKey
Sourcepub unsafe fn connectPeripheral_options(
&self,
peripheral: &CBPeripheral,
options: Option<&NSDictionary<NSString, AnyObject>>,
)
Available on crate features CBPeer
and CBPeripheral
only.
pub unsafe fn connectPeripheral_options( &self, peripheral: &CBPeripheral, options: Option<&NSDictionary<NSString, AnyObject>>, )
CBPeer
and CBPeripheral
only.Parameter peripheral
: The
CBPeripheral
to be connected.
Parameter options
: An optional dictionary specifying connection behavior options.
Initiates a connection to peripheral . Connection attempts never time out and, depending on the outcome, will result in a call to either {
centralManager:didConnectPeripheral:} or {@link centralManager:didFailToConnectPeripheral:error:}.
Pending attempts are cancelled automatically upon deallocation of <i>peripheral</i>, and explicitly via {@link cancelPeripheralConnection}.
@see centralManager:didConnectPeripheral:
@see centralManager:didFailToConnectPeripheral:error:
@seealso CBConnectPeripheralOptionNotifyOnConnectionKey
@seealso CBConnectPeripheralOptionNotifyOnDisconnectionKey
@seealso CBConnectPeripheralOptionNotifyOnNotificationKey
@seealso CBConnectPeripheralOptionEnableTransportBridgingKey
@seealso CBConnectPeripheralOptionRequiresANCS
@seealso CBConnectPeripheralOptionEnableAutoReconnect
Sourcepub unsafe fn cancelPeripheralConnection(&self, peripheral: &CBPeripheral)
Available on crate features CBPeer
and CBPeripheral
only.
pub unsafe fn cancelPeripheralConnection(&self, peripheral: &CBPeripheral)
CBPeer
and CBPeripheral
only.Parameter peripheral
: A
CBPeripheral
.
Cancels an active or pending connection to
peripheral
. Note that this is non-blocking, and any
CBPeripheral
commands that are still pending to
peripheral
may or may not complete.
See: centralManager:didDisconnectPeripheral:error:
Sourcepub unsafe fn registerForConnectionEventsWithOptions(
&self,
options: Option<&NSDictionary<CBConnectionEventMatchingOption, AnyObject>>,
)
Available on crate feature CBCentralManagerConstants
only.
pub unsafe fn registerForConnectionEventsWithOptions( &self, options: Option<&NSDictionary<CBConnectionEventMatchingOption, AnyObject>>, )
CBCentralManagerConstants
only.Parameter options
: A dictionary specifying connection event options.
Calls {
centralManager:connectionEventDidOccur:forPeripheral:} when a connection event occurs matching any of the given options.
Passing nil in the option parameter clears any prior registered matching options.
@see centralManager:connectionEventDidOccur:forPeripheral:
@seealso CBConnectionEventMatchingOptionServiceUUIDs
@seealso CBConnectionEventMatchingOptionPeripheralUUIDs
Methods from Deref<Target = CBManager>§
Sourcepub unsafe fn state(&self) -> CBManagerState
pub unsafe fn state(&self) -> CBManagerState
The current state of the manager, initially set to
CBManagerStateUnknown
.
Updates are provided by required delegate method {
managerDidUpdateState:}.
👎Deprecated
The current authorization of the manager, initially set to
CBManagerAuthorizationNotDetermined
.
Updates are provided by required delegate method {
managerDidUpdateState:}.
@seealso state
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 CBCentralManager
impl AsRef<AnyObject> for CBCentralManager
Source§impl AsRef<CBCentralManager> for CBCentralManager
impl AsRef<CBCentralManager> for CBCentralManager
Source§impl AsRef<CBManager> for CBCentralManager
impl AsRef<CBManager> for CBCentralManager
Source§impl AsRef<NSObject> for CBCentralManager
impl AsRef<NSObject> for CBCentralManager
Source§impl Borrow<AnyObject> for CBCentralManager
impl Borrow<AnyObject> for CBCentralManager
Source§impl Borrow<CBManager> for CBCentralManager
impl Borrow<CBManager> for CBCentralManager
Source§impl Borrow<NSObject> for CBCentralManager
impl Borrow<NSObject> for CBCentralManager
Source§impl ClassType for CBCentralManager
impl ClassType for CBCentralManager
Source§const NAME: &'static str = "CBCentralManager"
const NAME: &'static str = "CBCentralManager"
Source§type ThreadKind = <<CBCentralManager as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<CBCentralManager as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for CBCentralManager
impl Debug for CBCentralManager
Source§impl Deref for CBCentralManager
impl Deref for CBCentralManager
Source§impl Hash for CBCentralManager
impl Hash for CBCentralManager
Source§impl Message for CBCentralManager
impl Message for CBCentralManager
Source§impl NSObjectProtocol for CBCentralManager
impl NSObjectProtocol for CBCentralManager
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