objc2_watch_connectivity/generated/
WCSession.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/// [Apple's documentation](https://developer.apple.com/documentation/watchconnectivity/wcsessionactivationstate?language=objc)
11// NS_ENUM
12#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct WCSessionActivationState(pub NSInteger);
15impl WCSessionActivationState {
16    #[doc(alias = "WCSessionActivationStateNotActivated")]
17    pub const NotActivated: Self = Self(0);
18    #[doc(alias = "WCSessionActivationStateInactive")]
19    pub const Inactive: Self = Self(1);
20    #[doc(alias = "WCSessionActivationStateActivated")]
21    pub const Activated: Self = Self(2);
22}
23
24unsafe impl Encode for WCSessionActivationState {
25    const ENCODING: Encoding = NSInteger::ENCODING;
26}
27
28unsafe impl RefEncode for WCSessionActivationState {
29    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
30}
31
32extern_class!(
33    /// -------------------------------- WCSession --------------------------------
34    /// The default session is used to communicate between two counterpart apps
35    /// (i.e. iOS app and its native WatchKit extension). The session provides
36    /// methods for sending, receiving, and tracking state.
37    ///
38    /// On start up an app should set a delegate on the default session and call
39    /// activate. This will allow the system to populate the state properties and
40    /// deliver any outstanding background transfers.
41    ///
42    /// See also [Apple's documentation](https://developer.apple.com/documentation/watchconnectivity/wcsession?language=objc)
43    #[unsafe(super(NSObject))]
44    #[derive(Debug, PartialEq, Eq, Hash)]
45    pub struct WCSession;
46);
47
48unsafe impl NSObjectProtocol for WCSession {}
49
50impl WCSession {
51    extern_methods!(
52        /// Check if session is supported on this iOS device. Session is always available on WatchOS
53        #[unsafe(method(isSupported))]
54        #[unsafe(method_family = none)]
55        pub unsafe fn isSupported() -> bool;
56
57        /// Use the default session for all transferring of content and state monitoring.
58        #[unsafe(method(defaultSession))]
59        #[unsafe(method_family = none)]
60        pub unsafe fn defaultSession() -> Retained<WCSession>;
61
62        /// Use the default session instead.
63        #[unsafe(method(init))]
64        #[unsafe(method_family = init)]
65        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
66
67        /// A delegate must exist before the session will allow sends.
68        #[unsafe(method(delegate))]
69        #[unsafe(method_family = none)]
70        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn WCSessionDelegate>>>;
71
72        /// This is a [weak property][objc2::topics::weak_property].
73        /// Setter for [`delegate`][Self::delegate].
74        #[unsafe(method(setDelegate:))]
75        #[unsafe(method_family = none)]
76        pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn WCSessionDelegate>>);
77
78        /// The default session must be activated on startup before the session's properties contain correct values and will begin receiving delegate callbacks. Calling activate without a delegate set is undefined. If the WCSessionDelegate session:activationDidCompleteWithState:error: is implemented this method becomes an asynchronous call.
79        #[unsafe(method(activateSession))]
80        #[unsafe(method_family = none)]
81        pub unsafe fn activateSession(&self);
82
83        /// The state of the current session
84        #[unsafe(method(activationState))]
85        #[unsafe(method_family = none)]
86        pub unsafe fn activationState(&self) -> WCSessionActivationState;
87
88        /// Whether or not there is more content for the session to deliver
89        #[unsafe(method(hasContentPending))]
90        #[unsafe(method_family = none)]
91        pub unsafe fn hasContentPending(&self) -> bool;
92
93        /// Check if iOS device is paired to a watch
94        #[unsafe(method(isPaired))]
95        #[unsafe(method_family = none)]
96        pub unsafe fn isPaired(&self) -> bool;
97
98        /// Check if the user has the Watch app installed
99        #[unsafe(method(isWatchAppInstalled))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn isWatchAppInstalled(&self) -> bool;
102
103        /// Check if the user has the Watch app's complication enabled
104        #[unsafe(method(isComplicationEnabled))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn isComplicationEnabled(&self) -> bool;
107
108        /// The number of calls remaining to transferCurrentComplicationUserInfo: before the system starts transferring the complicationUserInfo as regular userInfos. If this is 0, the complicationUserInfo will be transferred as regular userInfos. Count will be 0 whenever the complication is not enabled
109        #[unsafe(method(remainingComplicationUserInfoTransfers))]
110        #[unsafe(method_family = none)]
111        pub unsafe fn remainingComplicationUserInfoTransfers(&self) -> NSUInteger;
112
113        /// Use this directory to persist any data specific to the selected Watch. The location of the URL will change when the selected Watch changes. This directory will be deleted upon next launch if the watch app is uninstalled for the selected Watch, or that Watch is unpaired. If the watch app is not installed for the selected Watch the value will be nil.
114        #[unsafe(method(watchDirectoryURL))]
115        #[unsafe(method_family = none)]
116        pub unsafe fn watchDirectoryURL(&self) -> Option<Retained<NSURL>>;
117
118        /// Check if the companion app is installed on the paired iPhone. This only applies to Watch apps that can run independently.
119        #[unsafe(method(isCompanionAppInstalled))]
120        #[unsafe(method_family = none)]
121        pub unsafe fn isCompanionAppInstalled(&self) -> bool;
122
123        /// The counterpart app must be reachable for a send message to succeed.
124        #[unsafe(method(isReachable))]
125        #[unsafe(method_family = none)]
126        pub unsafe fn isReachable(&self) -> bool;
127
128        /// Reachability in the Watch app requires the paired iOS device to have been unlocked at least once after reboot. This property can be used to determine if the iOS device needs to be unlocked. If the reachable property is set to NO it may be because the iOS device has rebooted and needs to be unlocked. If this is the case, the Watch can show a prompt to the user suggesting they unlock their paired iOS device.
129        #[unsafe(method(iOSDeviceNeedsUnlockAfterRebootForReachability))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn iOSDeviceNeedsUnlockAfterRebootForReachability(&self) -> bool;
132
133        #[cfg(feature = "block2")]
134        /// Clients can use this method to send messages to the counterpart app. Clients wishing to receive a reply to a particular message should pass in a replyHandler block. If the message cannot be sent or if the reply could not be received, the errorHandler block will be invoked with an error. If both a replyHandler and an errorHandler are specified, then exactly one of them will be invoked. Messages can only be sent while the sending app is running. If the sending app exits before the message is dispatched the send will fail. If the counterpart app is not running the counterpart app will be launched upon receiving the message (iOS counterpart app only). The message dictionary can only accept the property list types.
135        #[unsafe(method(sendMessage:replyHandler:errorHandler:))]
136        #[unsafe(method_family = none)]
137        pub unsafe fn sendMessage_replyHandler_errorHandler(
138            &self,
139            message: &NSDictionary<NSString, AnyObject>,
140            reply_handler: Option<
141                &block2::Block<dyn Fn(NonNull<NSDictionary<NSString, AnyObject>>)>,
142            >,
143            error_handler: Option<&block2::Block<dyn Fn(NonNull<NSError>)>>,
144        );
145
146        #[cfg(feature = "block2")]
147        /// Clients can use this method to send message data. All the policies of send message apply to send message data. Send message data is meant for clients that have an existing transfer format and do not need the convenience of the send message dictionary.
148        #[unsafe(method(sendMessageData:replyHandler:errorHandler:))]
149        #[unsafe(method_family = none)]
150        pub unsafe fn sendMessageData_replyHandler_errorHandler(
151            &self,
152            data: &NSData,
153            reply_handler: Option<&block2::Block<dyn Fn(NonNull<NSData>)>>,
154            error_handler: Option<&block2::Block<dyn Fn(NonNull<NSError>)>>,
155        );
156
157        /// Setting the applicationContext is a way to transfer the latest state of an app. After updating the applicationContext, the system initiates the data transfer at an appropriate time, which can occur after the app exits. The counterpart app will receive a delegate callback on next launch if the applicationContext has successfully arrived. If there is no app context, it should be updated with an empty dictionary. The applicationContext dictionary can only accept the property list types.
158        #[unsafe(method(applicationContext))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn applicationContext(&self) -> Retained<NSDictionary<NSString, AnyObject>>;
161
162        #[unsafe(method(updateApplicationContext:error:_))]
163        #[unsafe(method_family = none)]
164        pub unsafe fn updateApplicationContext_error(
165            &self,
166            application_context: &NSDictionary<NSString, AnyObject>,
167        ) -> Result<(), Retained<NSError>>;
168
169        /// Stores the most recently received applicationContext from the counterpart app.
170        #[unsafe(method(receivedApplicationContext))]
171        #[unsafe(method_family = none)]
172        pub unsafe fn receivedApplicationContext(
173            &self,
174        ) -> Retained<NSDictionary<NSString, AnyObject>>;
175
176        #[cfg(feature = "WCSessionUserInfoTransfer")]
177        /// The system will enqueue the user info dictionary and transfer it to the counterpart app at an opportune time. The transfer of user info will continue after the sending app has exited. The counterpart app will receive a delegate callback on next launch if the file has successfully arrived. The userInfo dictionary can only accept the property list types.
178        #[unsafe(method(transferUserInfo:))]
179        #[unsafe(method_family = none)]
180        pub unsafe fn transferUserInfo(
181            &self,
182            user_info: &NSDictionary<NSString, AnyObject>,
183        ) -> Retained<WCSessionUserInfoTransfer>;
184
185        #[cfg(feature = "WCSessionUserInfoTransfer")]
186        /// Enqueues a user info dictionary containing the most current information for an enabled complication. If the app's complication is enabled the system will try to transfer this user info immediately. Once a current complication user info is received the system will launch the Watch App Extension in the background and allow it to update the complication content. If the current user info cannot be transferred (i.e. devices disconnected, out of background launch budget, etc.) it will wait in the outstandingUserInfoTransfers queue until next opportune time. There can only be one current complication user info in the outstandingUserInfoTransfers queue. If a current complication user info is outstanding (waiting to transfer) and -transferCurrentComplicationUserInfo: is called again with new user info, the new user info will be tagged as current and the previously current user info will be untagged. The previous user info will however stay in the queue of outstanding transfers.
187        #[unsafe(method(transferCurrentComplicationUserInfo:))]
188        #[unsafe(method_family = none)]
189        pub unsafe fn transferCurrentComplicationUserInfo(
190            &self,
191            user_info: &NSDictionary<NSString, AnyObject>,
192        ) -> Retained<WCSessionUserInfoTransfer>;
193
194        #[cfg(feature = "WCSessionUserInfoTransfer")]
195        /// Returns an array of user info transfers that are still transferring (i.e. have not been cancelled, failed, or been received by the counterpart app).
196        #[unsafe(method(outstandingUserInfoTransfers))]
197        #[unsafe(method_family = none)]
198        pub unsafe fn outstandingUserInfoTransfers(
199            &self,
200        ) -> Retained<NSArray<WCSessionUserInfoTransfer>>;
201
202        #[cfg(feature = "WCSessionFile")]
203        /// The system will enqueue the file and transfer it to the counterpart app at an opportune time. The transfer of a file will continue after the sending app has exited. The counterpart app will receive a delegate callback on next launch if the file has successfully arrived. The metadata dictionary can only accept the property list types.
204        #[unsafe(method(transferFile:metadata:))]
205        #[unsafe(method_family = none)]
206        pub unsafe fn transferFile_metadata(
207            &self,
208            file: &NSURL,
209            metadata: Option<&NSDictionary<NSString, AnyObject>>,
210        ) -> Retained<WCSessionFileTransfer>;
211
212        #[cfg(feature = "WCSessionFile")]
213        /// Returns an array of file transfers that are still transferring (i.e. have not been cancelled, failed, or been received by the counterpart app).
214        #[unsafe(method(outstandingFileTransfers))]
215        #[unsafe(method_family = none)]
216        pub unsafe fn outstandingFileTransfers(&self) -> Retained<NSArray<WCSessionFileTransfer>>;
217    );
218}
219
220/// Methods declared on superclass `NSObject`.
221impl WCSession {
222    extern_methods!(
223        #[unsafe(method(new))]
224        #[unsafe(method_family = new)]
225        pub unsafe fn new() -> Retained<Self>;
226    );
227}
228
229extern_protocol!(
230    /// ----------------------------- WCSessionDelegate -----------------------------
231    /// The session calls the delegate methods when content is received and session
232    /// state changes. All delegate methods will be called on the same queue. The
233    /// delegate queue is a non-main serial queue. It is the client's responsibility
234    /// to dispatch to another queue if neccessary.
235    ///
236    /// See also [Apple's documentation](https://developer.apple.com/documentation/watchconnectivity/wcsessiondelegate?language=objc)
237    pub unsafe trait WCSessionDelegate: NSObjectProtocol {
238        /// Called when the session has completed activation. If session state is WCSessionActivationStateNotActivated there will be an error with more details.
239        #[unsafe(method(session:activationDidCompleteWithState:error:))]
240        #[unsafe(method_family = none)]
241        unsafe fn session_activationDidCompleteWithState_error(
242            &self,
243            session: &WCSession,
244            activation_state: WCSessionActivationState,
245            error: Option<&NSError>,
246        );
247
248        /// Called when the session can no longer be used to modify or add any new transfers and, all interactive messages will be cancelled, but delegate callbacks for background transfers can still occur. This will happen when the selected watch is being changed.
249        #[unsafe(method(sessionDidBecomeInactive:))]
250        #[unsafe(method_family = none)]
251        unsafe fn sessionDidBecomeInactive(&self, session: &WCSession);
252
253        /// Called when all delegate callbacks for the previously selected watch has occurred. The session can be re-activated for the now selected watch using activateSession.
254        #[unsafe(method(sessionDidDeactivate:))]
255        #[unsafe(method_family = none)]
256        unsafe fn sessionDidDeactivate(&self, session: &WCSession);
257
258        /// Called when any of the Watch state properties change.
259        #[optional]
260        #[unsafe(method(sessionWatchStateDidChange:))]
261        #[unsafe(method_family = none)]
262        unsafe fn sessionWatchStateDidChange(&self, session: &WCSession);
263
264        /// Called when the installed state of the Companion app changes.
265        #[optional]
266        #[unsafe(method(sessionCompanionAppInstalledDidChange:))]
267        #[unsafe(method_family = none)]
268        unsafe fn sessionCompanionAppInstalledDidChange(&self, session: &WCSession);
269
270        /// Called when the reachable state of the counterpart app changes. The receiver should check the reachable property on receiving this delegate callback.
271        #[optional]
272        #[unsafe(method(sessionReachabilityDidChange:))]
273        #[unsafe(method_family = none)]
274        unsafe fn sessionReachabilityDidChange(&self, session: &WCSession);
275
276        /// Called on the delegate of the receiver. Will be called on startup if the incoming message caused the receiver to launch.
277        #[optional]
278        #[unsafe(method(session:didReceiveMessage:))]
279        #[unsafe(method_family = none)]
280        unsafe fn session_didReceiveMessage(
281            &self,
282            session: &WCSession,
283            message: &NSDictionary<NSString, AnyObject>,
284        );
285
286        #[cfg(feature = "block2")]
287        /// Called on the delegate of the receiver when the sender sends a message that expects a reply. Will be called on startup if the incoming message caused the receiver to launch.
288        #[optional]
289        #[unsafe(method(session:didReceiveMessage:replyHandler:))]
290        #[unsafe(method_family = none)]
291        unsafe fn session_didReceiveMessage_replyHandler(
292            &self,
293            session: &WCSession,
294            message: &NSDictionary<NSString, AnyObject>,
295            reply_handler: &block2::Block<dyn Fn(NonNull<NSDictionary<NSString, AnyObject>>)>,
296        );
297
298        /// Called on the delegate of the receiver. Will be called on startup if the incoming message data caused the receiver to launch.
299        #[optional]
300        #[unsafe(method(session:didReceiveMessageData:))]
301        #[unsafe(method_family = none)]
302        unsafe fn session_didReceiveMessageData(&self, session: &WCSession, message_data: &NSData);
303
304        #[cfg(feature = "block2")]
305        /// Called on the delegate of the receiver when the sender sends message data that expects a reply. Will be called on startup if the incoming message data caused the receiver to launch.
306        #[optional]
307        #[unsafe(method(session:didReceiveMessageData:replyHandler:))]
308        #[unsafe(method_family = none)]
309        unsafe fn session_didReceiveMessageData_replyHandler(
310            &self,
311            session: &WCSession,
312            message_data: &NSData,
313            reply_handler: &block2::Block<dyn Fn(NonNull<NSData>)>,
314        );
315
316        /// Called on the delegate of the receiver. Will be called on startup if an applicationContext is available.
317        #[optional]
318        #[unsafe(method(session:didReceiveApplicationContext:))]
319        #[unsafe(method_family = none)]
320        unsafe fn session_didReceiveApplicationContext(
321            &self,
322            session: &WCSession,
323            application_context: &NSDictionary<NSString, AnyObject>,
324        );
325
326        #[cfg(feature = "WCSessionUserInfoTransfer")]
327        /// Called on the sending side after the user info transfer has successfully completed or failed with an error. Will be called on next launch if the sender was not running when the user info finished.
328        #[optional]
329        #[unsafe(method(session:didFinishUserInfoTransfer:error:))]
330        #[unsafe(method_family = none)]
331        unsafe fn session_didFinishUserInfoTransfer_error(
332            &self,
333            session: &WCSession,
334            user_info_transfer: &WCSessionUserInfoTransfer,
335            error: Option<&NSError>,
336        );
337
338        /// Called on the delegate of the receiver. Will be called on startup if the user info finished transferring when the receiver was not running.
339        #[optional]
340        #[unsafe(method(session:didReceiveUserInfo:))]
341        #[unsafe(method_family = none)]
342        unsafe fn session_didReceiveUserInfo(
343            &self,
344            session: &WCSession,
345            user_info: &NSDictionary<NSString, AnyObject>,
346        );
347
348        #[cfg(feature = "WCSessionFile")]
349        /// Called on the sending side after the file transfer has successfully completed or failed with an error. Will be called on next launch if the sender was not running when the transfer finished.
350        #[optional]
351        #[unsafe(method(session:didFinishFileTransfer:error:))]
352        #[unsafe(method_family = none)]
353        unsafe fn session_didFinishFileTransfer_error(
354            &self,
355            session: &WCSession,
356            file_transfer: &WCSessionFileTransfer,
357            error: Option<&NSError>,
358        );
359
360        #[cfg(feature = "WCSessionFile")]
361        /// Called on the delegate of the receiver. Will be called on startup if the file finished transferring when the receiver was not running. The incoming file will be located in the Documents/Inbox/ folder when being delivered. The receiver must take ownership of the file by moving it to another location. The system will remove any content that has not been moved when this delegate method returns.
362        #[optional]
363        #[unsafe(method(session:didReceiveFile:))]
364        #[unsafe(method_family = none)]
365        unsafe fn session_didReceiveFile(&self, session: &WCSession, file: &WCSessionFile);
366    }
367);