objc2-safety-kit 0.3.2

Bindings to the SafetyKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

/// This enumeration defines the status of requested voice call
///
/// See also: SAEmergencyResponseManagerVoiceCallStatus
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/safetykit/saemergencyresponsemanagervoicecallstatus?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SAEmergencyResponseManagerVoiceCallStatus(pub NSInteger);
impl SAEmergencyResponseManagerVoiceCallStatus {
    #[doc(alias = "SAEmergencyResponseManagerVoiceCallStatusDialing")]
    pub const Dialing: Self = Self(0);
    /// <
    /// the system is dialing the voice call
    #[doc(alias = "SAEmergencyResponseManagerVoiceCallStatusActive")]
    pub const Active: Self = Self(1);
    /// the system dialed voice call is disconnected after being active
    #[doc(alias = "SAEmergencyResponseManagerVoiceCallStatusDisconnected")]
    pub const Disconnected: Self = Self(2);
    /// the system dialed voice call failed to connect
    #[doc(alias = "SAEmergencyResponseManagerVoiceCallStatusFailed")]
    pub const Failed: Self = Self(3);
}

unsafe impl Encode for SAEmergencyResponseManagerVoiceCallStatus {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for SAEmergencyResponseManagerVoiceCallStatus {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// SAEmergencyResponseManager
    ///
    ///
    /// Use SAEmergencyResponseManager to request actions in response to an emergency event.
    /// Set the delegate to monitor the progress of requested emergency response actions.
    /// SAEmergencyResponseManager requires user authorization for at least one of the emergency event detections e.g. SACrashDetectionEvent
    ///
    /// SAEmergencyResponseManager requires an entitlement from Apple to at least one of the emergency event detections. To apply for the entitlement, see respective detection mechanisms
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/safetykit/saemergencyresponsemanager?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct SAEmergencyResponseManager;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for SAEmergencyResponseManager {}
);

impl SAEmergencyResponseManager {
    extern_methods!(
        /// delegate
        ///
        ///
        /// The delegate object to receive updates about requested emergency response action.
        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn SAEmergencyResponseDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn SAEmergencyResponseDelegate>>,
        );

        #[cfg(feature = "block2")]
        /// Requests the system to dial a voice call on behalf of the user.
        /// Apps running in the background / foreground can request to dial a voice call without user confirmation. Emergency numbers are not allowed.
        /// Requests are accepted only if user has authorized the app to receive and handle emergency detection events and only for a limited time after an emergency event is detected.
        ///
        ///
        /// See also: SAEmergencyResponseDelegate
        ///
        ///
        /// Parameter `phoneNumber`: Apps can request the system to dial a voice call by providing a phone number. Emergency numbers are not allowed.
        ///
        ///
        /// Parameter `handler`: Completion handler invoked with the status of the voice call request.
        /// If requested is accepted, the handler is invoked with a nil error. Interpret the error returned using SAErrorDomain.
        /// Requests will fail with SAErrorNotAuthorized if user has not authorized the app to receive and handle any emergency events.
        /// Requests will fail with SAErrorNotAvailable if invoked outside of the limited time window after an emergency event is detected.
        /// Use the SAEmergencyResponseDelegate to monitor the progress of the voice call.
        #[unsafe(method(dialVoiceCallToPhoneNumber:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn dialVoiceCallToPhoneNumber_completionHandler(
            &self,
            phone_number: &NSString,
            handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl SAEmergencyResponseManager {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_protocol!(
    /// SAEmergencyResponseDelegate
    ///
    ///
    /// SAEmergencyResponseManager notifies its delegate about status of the requested emergency response action
    ///
    ///
    /// See also: SAEmergencyResponseManager
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/safetykit/saemergencyresponsedelegate?language=objc)
    pub unsafe trait SAEmergencyResponseDelegate: NSObjectProtocol {
        /// Voice call can be requested when running in the foreground or background within a limited time window of a detected emergency event,
        /// Use this delegate to monitor the status of the requested voice call.
        #[optional]
        #[unsafe(method(emergencyResponseManager:didUpdateVoiceCallStatus:))]
        #[unsafe(method_family = none)]
        unsafe fn emergencyResponseManager_didUpdateVoiceCallStatus(
            &self,
            emergency_response_manager: &SAEmergencyResponseManager,
            voice_call_status: SAEmergencyResponseManagerVoiceCallStatus,
        );
    }
);