objc2_watch_kit/generated/
WKExtendedRuntimeSession.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Defines the potential states the session can be in
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/watchkit/wkextendedruntimesessionstate?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct WKExtendedRuntimeSessionState(pub NSInteger);
17impl WKExtendedRuntimeSessionState {
18    /// Start has never been called on the session.
19    #[doc(alias = "WKExtendedRuntimeSessionStateNotStarted")]
20    pub const NotStarted: Self = Self(0);
21    /// The session has been successfully scheduled to start at a future date, as specified by date passed to startAtDate.
22    #[doc(alias = "WKExtendedRuntimeSessionStateScheduled")]
23    pub const Scheduled: Self = Self(1);
24    /// The session is actively running.
25    #[doc(alias = "WKExtendedRuntimeSessionStateRunning")]
26    pub const Running: Self = Self(2);
27    /// The session is not running. Either the session ended, or hit an error. See WKExtendedRuntimeSessionInvalidationReason for a list of reasons why the session could be invalid.
28    #[doc(alias = "WKExtendedRuntimeSessionStateInvalid")]
29    pub const Invalid: Self = Self(3);
30}
31
32unsafe impl Encode for WKExtendedRuntimeSessionState {
33    const ENCODING: Encoding = NSInteger::ENCODING;
34}
35
36unsafe impl RefEncode for WKExtendedRuntimeSessionState {
37    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
38}
39
40/// Defines the reasons for which a session may become invalid.
41///
42/// See also [Apple's documentation](https://developer.apple.com/documentation/watchkit/wkextendedruntimesessioninvalidationreason?language=objc)
43// NS_ENUM
44#[repr(transparent)]
45#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
46pub struct WKExtendedRuntimeSessionInvalidationReason(pub NSInteger);
47impl WKExtendedRuntimeSessionInvalidationReason {
48    /// The session ended normally, likely through a direct call to invalidate.
49    #[doc(alias = "WKExtendedRuntimeSessionInvalidationReasonNone")]
50    pub const None: Self = Self(0);
51    /// A session for this application has already been started, and is currently running, another session can not be started.
52    #[doc(alias = "WKExtendedRuntimeSessionInvalidationReasonSessionInProgress")]
53    pub const SessionInProgress: Self = Self(1);
54    /// The session hit its time limit, as noted by its expiration date.
55    #[doc(alias = "WKExtendedRuntimeSessionInvalidationReasonExpired")]
56    pub const Expired: Self = Self(2);
57    /// The application has lost frontmost status, so the session ended.
58    /// Examples of actions by the user which cause the session to lose frontmost status include:
59    /// User pressing digital crown, tapping on a notification to go to another application,
60    /// switching applications through the dock, or any other apps entering the foreground.
61    #[doc(alias = "WKExtendedRuntimeSessionInvalidationReasonResignedFrontmost")]
62    pub const ResignedFrontmost: Self = Self(3);
63    /// Apple Watch is in a state that doesn't currently allow this session type to run.
64    #[doc(alias = "WKExtendedRuntimeSessionInvalidationReasonSuppressedBySystem")]
65    pub const SuppressedBySystem: Self = Self(4);
66    /// The session did not end normally, and there is an error returned with more information.
67    #[doc(alias = "WKExtendedRuntimeSessionInvalidationReasonError")]
68    pub const Error: Self = Self(-1);
69}
70
71unsafe impl Encode for WKExtendedRuntimeSessionInvalidationReason {
72    const ENCODING: Encoding = NSInteger::ENCODING;
73}
74
75unsafe impl RefEncode for WKExtendedRuntimeSessionInvalidationReason {
76    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
77}
78
79extern "C" {
80    /// [Apple's documentation](https://developer.apple.com/documentation/watchkit/wkextendedruntimesessionerrordomain?language=objc)
81    pub static WKExtendedRuntimeSessionErrorDomain: &'static NSString;
82}
83
84/// [Apple's documentation](https://developer.apple.com/documentation/watchkit/wkextendedruntimesessionerrorcode?language=objc)
85// NS_ENUM
86#[repr(transparent)]
87#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
88pub struct WKExtendedRuntimeSessionErrorCode(pub NSInteger);
89impl WKExtendedRuntimeSessionErrorCode {
90    #[doc(alias = "WKExtendedRuntimeSessionErrorUnknown")]
91    pub const Unknown: Self = Self(1);
92    #[doc(alias = "WKExtendedRuntimeSessionErrorScheduledTooFarInAdvance")]
93    pub const ScheduledTooFarInAdvance: Self = Self(2);
94    #[doc(alias = "WKExtendedRuntimeSessionErrorMustBeActiveToStartOrSchedule")]
95    pub const MustBeActiveToStartOrSchedule: Self = Self(3);
96    #[doc(alias = "WKExtendedRuntimeSessionErrorNotYetStarted")]
97    pub const NotYetStarted: Self = Self(4);
98    #[doc(alias = "WKExtendedRuntimeSessionErrorExceededResourceLimits")]
99    pub const ExceededResourceLimits: Self = Self(5);
100    #[doc(alias = "WKExtendedRuntimeSessionErrorBARDisabled")]
101    pub const BARDisabled: Self = Self(6);
102    #[doc(alias = "WKExtendedRuntimeSessionErrorNotApprovedToStartSession")]
103    pub const NotApprovedToStartSession: Self = Self(7);
104    #[doc(alias = "WKExtendedRuntimeSessionErrorNotApprovedToSchedule")]
105    pub const NotApprovedToSchedule: Self = Self(8);
106    #[doc(alias = "WKExtendedRuntimeSessionErrorMustBeActiveToPrompt")]
107    pub const MustBeActiveToPrompt: Self = Self(9);
108    #[doc(alias = "WKExtendedRuntimeSessionErrorUnsupportedSessionType")]
109    pub const UnsupportedSessionType: Self = Self(10);
110}
111
112unsafe impl Encode for WKExtendedRuntimeSessionErrorCode {
113    const ENCODING: Encoding = NSInteger::ENCODING;
114}
115
116unsafe impl RefEncode for WKExtendedRuntimeSessionErrorCode {
117    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
118}
119
120/// [Apple's documentation](https://developer.apple.com/documentation/watchkit/wkextendedruntimesessionautolaunchauthorizationstatus?language=objc)
121// NS_ENUM
122#[repr(transparent)]
123#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
124pub struct WKExtendedRuntimeSessionAutoLaunchAuthorizationStatus(pub NSInteger);
125impl WKExtendedRuntimeSessionAutoLaunchAuthorizationStatus {
126    #[doc(alias = "WKExtendedRuntimeSessionAutoLaunchAuthorizationStatusUnknown")]
127    pub const Unknown: Self = Self(0);
128    #[doc(alias = "WKExtendedRuntimeSessionAutoLaunchAuthorizationStatusInactive")]
129    pub const Inactive: Self = Self(1);
130    #[doc(alias = "WKExtendedRuntimeSessionAutoLaunchAuthorizationStatusActive")]
131    pub const Active: Self = Self(2);
132}
133
134unsafe impl Encode for WKExtendedRuntimeSessionAutoLaunchAuthorizationStatus {
135    const ENCODING: Encoding = NSInteger::ENCODING;
136}
137
138unsafe impl RefEncode for WKExtendedRuntimeSessionAutoLaunchAuthorizationStatus {
139    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
140}
141
142extern_class!(
143    /// [Apple's documentation](https://developer.apple.com/documentation/watchkit/wkextendedruntimesession?language=objc)
144    #[unsafe(super(NSObject))]
145    #[derive(Debug, PartialEq, Eq, Hash)]
146    pub struct WKExtendedRuntimeSession;
147);
148
149extern_conformance!(
150    unsafe impl NSObjectProtocol for WKExtendedRuntimeSession {}
151);
152
153impl WKExtendedRuntimeSession {
154    extern_methods!(
155        /// This method will create a session, with the capabilities granted for the appropriate session type specified in the "Background Modes" capability in Xcode.
156        #[unsafe(method(session))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn session() -> Retained<WKExtendedRuntimeSession>;
159
160        #[cfg(feature = "block2")]
161        /// Request auto-launch authorization for the current app. This may trigger prompt to the user asking if they
162        /// want to make the current app the app to launch automatically when system conditions are met for the app's
163        /// supported session type. This prompt will only be shown to the user once per application.
164        /// The completion handler will be called with an error if the application's session type does not support auto-launch,
165        /// or if the app is not foreground and has not yet triggered a prompt.
166        #[unsafe(method(requestAutoLaunchAuthorizationStatusWithCompletion:))]
167        #[unsafe(method_family = none)]
168        pub unsafe fn requestAutoLaunchAuthorizationStatusWithCompletion(
169            completion: &block2::DynBlock<
170                dyn Fn(WKExtendedRuntimeSessionAutoLaunchAuthorizationStatus, *mut NSError),
171            >,
172        );
173
174        /// Setting a delegate on the session provides you with updates on when the session begins,
175        /// ends, or, encounters an error. Be sure to set a delegate before calling start, to receive the sessionDidStart callback.
176        #[unsafe(method(delegate))]
177        #[unsafe(method_family = none)]
178        pub unsafe fn delegate(
179            &self,
180        ) -> Option<Retained<ProtocolObject<dyn WKExtendedRuntimeSessionDelegate>>>;
181
182        /// Setter for [`delegate`][Self::delegate].
183        ///
184        /// This is a [weak property][objc2::topics::weak_property].
185        #[unsafe(method(setDelegate:))]
186        #[unsafe(method_family = none)]
187        pub unsafe fn setDelegate(
188            &self,
189            delegate: Option<&ProtocolObject<dyn WKExtendedRuntimeSessionDelegate>>,
190        );
191
192        /// The current state of the session.
193        #[unsafe(method(state))]
194        #[unsafe(method_family = none)]
195        pub unsafe fn state(&self) -> WKExtendedRuntimeSessionState;
196
197        /// The date at which the session will no longer receive runtime.
198        /// Use this date to figure out how much time there is left to run before the end of the session.
199        /// If the session has not yet started, this value will be nil. If the session successfully starts,
200        /// this date will then be valid, even after the session gets invalidated.
201        #[unsafe(method(expirationDate))]
202        #[unsafe(method_family = none)]
203        pub unsafe fn expirationDate(&self) -> Option<Retained<NSDate>>;
204
205        /// Starts the session.
206        #[unsafe(method(start))]
207        #[unsafe(method_family = none)]
208        pub unsafe fn start(&self);
209
210        /// Parameter `date`: A date in the future when the session should start running.
211        ///
212        /// Use this method to schedule the session to run at future date. Calling this API must be done while the application is in the foreground, but the session will start at the appropriate date regardless of application state. This method can only be used for the alarm background mode.
213        #[unsafe(method(startAtDate:))]
214        #[unsafe(method_family = none)]
215        pub unsafe fn startAtDate(&self, date: &NSDate);
216
217        /// This method will end a session early before its expiration date.
218        /// If this method is called on a session scheduled through startAtDate, the session will no longer be scheduled to run.
219        /// Once invalidate is called on a session, it can no longer run.
220        #[unsafe(method(invalidate))]
221        #[unsafe(method_family = none)]
222        pub unsafe fn invalidate(&self);
223
224        #[cfg(all(feature = "WKInterfaceDevice", feature = "block2"))]
225        /// Parameter `type`: Haptic type to play
226        ///
227        /// Parameter `repeatHandler`: an optional block that returns a valid time interval for when to play the next haptic. This value must be > 0.0 and
228        /// <
229        /// = 60.0. This block also optionally allows the app to change the haptic type that is played by modifying outHapticType. If repeatHandler is NULL, a system default value is used for the repeat interval.
230        ///
231        /// Use this method to start playing a repeating haptic to alert the user. If the app is not active, this will result in a system alert UI. The haptic will repeat at the interval specified by the block in the repeatHandler parameter or at a default interval if repeatHandler is not specified. The haptic will continue playing until one of the following happens:
232        /// 1) the user taps the stop button in the system alarm alert, ending the session
233        /// 2) the session is invalidated by the app while the app is in an active UI state
234        ///
235        /// This method can only be called on a WKExtendedRuntimeSession that was scheduled with startAtDate: and currently has a state of WKExtendedRuntimeSessionStateRunning. If it is called outside that time, it will be ignored.
236        #[unsafe(method(notifyUserWithHaptic:repeatHandler:))]
237        #[unsafe(method_family = none)]
238        pub unsafe fn notifyUserWithHaptic_repeatHandler(
239            &self,
240            r#type: WKHapticType,
241            repeat_handler: Option<
242                &block2::DynBlock<dyn Fn(NonNull<WKHapticType>) -> NSTimeInterval>,
243            >,
244        );
245    );
246}
247
248/// Methods declared on superclass `NSObject`.
249impl WKExtendedRuntimeSession {
250    extern_methods!(
251        #[unsafe(method(init))]
252        #[unsafe(method_family = init)]
253        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
254
255        #[unsafe(method(new))]
256        #[unsafe(method_family = new)]
257        pub unsafe fn new() -> Retained<Self>;
258    );
259}
260
261extern_protocol!(
262    /// [Apple's documentation](https://developer.apple.com/documentation/watchkit/wkextendedruntimesessiondelegate?language=objc)
263    pub unsafe trait WKExtendedRuntimeSessionDelegate: NSObjectProtocol {
264        /// Parameter `extendedRuntimeSession`: The session which has been invalidated
265        ///
266        /// Parameter `reason`: The termination reason explaining why the session has been invalidated.
267        ///
268        /// Parameter `error`: If reason is WKExtendedRuntimeSessionInvalidationReasonError, this object will represent that error.
269        ///
270        /// This is called if a session fails to start, or when it ends once it has started. See WKExtendedRuntimeSeesionInvalidationReason for the
271        /// reasons this may be called.
272        #[unsafe(method(extendedRuntimeSession:didInvalidateWithReason:error:))]
273        #[unsafe(method_family = none)]
274        unsafe fn extendedRuntimeSession_didInvalidateWithReason_error(
275            &self,
276            extended_runtime_session: &WKExtendedRuntimeSession,
277            reason: WKExtendedRuntimeSessionInvalidationReason,
278            error: Option<&NSError>,
279        );
280
281        /// Parameter `extendedRuntimeSession`: The session which started
282        ///
283        /// Called when the session has started successfully.
284        #[unsafe(method(extendedRuntimeSessionDidStart:))]
285        #[unsafe(method_family = none)]
286        unsafe fn extendedRuntimeSessionDidStart(
287            &self,
288            extended_runtime_session: &WKExtendedRuntimeSession,
289        );
290
291        /// Parameter `extendedRuntimeSession`: The session which is about to expire.
292        ///
293        /// Delegate method provided to application to signify the session will expire soon.
294        /// All tasks must be completed before the expiration date.
295        #[unsafe(method(extendedRuntimeSessionWillExpire:))]
296        #[unsafe(method_family = none)]
297        unsafe fn extendedRuntimeSessionWillExpire(
298            &self,
299            extended_runtime_session: &WKExtendedRuntimeSession,
300        );
301    }
302);