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
48extern_conformance!(
49 unsafe impl NSObjectProtocol for WCSession {}
50);
51
52impl WCSession {
53 extern_methods!(
54 /// Check if session is supported on this iOS device. Session is always available on WatchOS
55 #[unsafe(method(isSupported))]
56 #[unsafe(method_family = none)]
57 pub unsafe fn isSupported() -> bool;
58
59 /// Use the default session for all transferring of content and state monitoring.
60 #[unsafe(method(defaultSession))]
61 #[unsafe(method_family = none)]
62 pub unsafe fn defaultSession() -> Retained<WCSession>;
63
64 /// Use the default session instead.
65 #[unsafe(method(init))]
66 #[unsafe(method_family = init)]
67 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
68
69 /// A delegate must exist before the session will allow sends.
70 #[unsafe(method(delegate))]
71 #[unsafe(method_family = none)]
72 pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn WCSessionDelegate>>>;
73
74 /// Setter for [`delegate`][Self::delegate].
75 ///
76 /// This is a [weak property][objc2::topics::weak_property].
77 #[unsafe(method(setDelegate:))]
78 #[unsafe(method_family = none)]
79 pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn WCSessionDelegate>>);
80
81 /// 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.
82 #[unsafe(method(activateSession))]
83 #[unsafe(method_family = none)]
84 pub unsafe fn activateSession(&self);
85
86 /// The state of the current session
87 #[unsafe(method(activationState))]
88 #[unsafe(method_family = none)]
89 pub unsafe fn activationState(&self) -> WCSessionActivationState;
90
91 /// Whether or not there is more content for the session to deliver
92 #[unsafe(method(hasContentPending))]
93 #[unsafe(method_family = none)]
94 pub unsafe fn hasContentPending(&self) -> bool;
95
96 /// Check if iOS device is paired to a watch
97 #[unsafe(method(isPaired))]
98 #[unsafe(method_family = none)]
99 pub unsafe fn isPaired(&self) -> bool;
100
101 /// Check if the user has the Watch app installed
102 #[unsafe(method(isWatchAppInstalled))]
103 #[unsafe(method_family = none)]
104 pub unsafe fn isWatchAppInstalled(&self) -> bool;
105
106 /// Check if the user has the Watch app's complication enabled
107 #[unsafe(method(isComplicationEnabled))]
108 #[unsafe(method_family = none)]
109 pub unsafe fn isComplicationEnabled(&self) -> bool;
110
111 /// 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
112 #[unsafe(method(remainingComplicationUserInfoTransfers))]
113 #[unsafe(method_family = none)]
114 pub unsafe fn remainingComplicationUserInfoTransfers(&self) -> NSUInteger;
115
116 /// 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.
117 #[unsafe(method(watchDirectoryURL))]
118 #[unsafe(method_family = none)]
119 pub unsafe fn watchDirectoryURL(&self) -> Option<Retained<NSURL>>;
120
121 /// Check if the companion app is installed on the paired iPhone. This only applies to Watch apps that can run independently.
122 #[unsafe(method(isCompanionAppInstalled))]
123 #[unsafe(method_family = none)]
124 pub unsafe fn isCompanionAppInstalled(&self) -> bool;
125
126 /// The counterpart app must be reachable for a send message to succeed.
127 #[unsafe(method(isReachable))]
128 #[unsafe(method_family = none)]
129 pub unsafe fn isReachable(&self) -> bool;
130
131 /// 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.
132 #[unsafe(method(iOSDeviceNeedsUnlockAfterRebootForReachability))]
133 #[unsafe(method_family = none)]
134 pub unsafe fn iOSDeviceNeedsUnlockAfterRebootForReachability(&self) -> bool;
135
136 #[cfg(feature = "block2")]
137 /// 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.
138 ///
139 /// # Safety
140 ///
141 /// `message` generic should be of the correct type.
142 #[unsafe(method(sendMessage:replyHandler:errorHandler:))]
143 #[unsafe(method_family = none)]
144 pub unsafe fn sendMessage_replyHandler_errorHandler(
145 &self,
146 message: &NSDictionary<NSString, AnyObject>,
147 reply_handler: Option<
148 &block2::DynBlock<dyn Fn(NonNull<NSDictionary<NSString, AnyObject>>)>,
149 >,
150 error_handler: Option<&block2::DynBlock<dyn Fn(NonNull<NSError>)>>,
151 );
152
153 #[cfg(feature = "block2")]
154 /// 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.
155 #[unsafe(method(sendMessageData:replyHandler:errorHandler:))]
156 #[unsafe(method_family = none)]
157 pub unsafe fn sendMessageData_replyHandler_errorHandler(
158 &self,
159 data: &NSData,
160 reply_handler: Option<&block2::DynBlock<dyn Fn(NonNull<NSData>)>>,
161 error_handler: Option<&block2::DynBlock<dyn Fn(NonNull<NSError>)>>,
162 );
163
164 /// 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.
165 #[unsafe(method(applicationContext))]
166 #[unsafe(method_family = none)]
167 pub unsafe fn applicationContext(&self) -> Retained<NSDictionary<NSString, AnyObject>>;
168
169 /// # Safety
170 ///
171 /// `application_context` generic should be of the correct type.
172 #[unsafe(method(updateApplicationContext:error:_))]
173 #[unsafe(method_family = none)]
174 pub unsafe fn updateApplicationContext_error(
175 &self,
176 application_context: &NSDictionary<NSString, AnyObject>,
177 ) -> Result<(), Retained<NSError>>;
178
179 /// Stores the most recently received applicationContext from the counterpart app.
180 #[unsafe(method(receivedApplicationContext))]
181 #[unsafe(method_family = none)]
182 pub unsafe fn receivedApplicationContext(
183 &self,
184 ) -> Retained<NSDictionary<NSString, AnyObject>>;
185
186 #[cfg(feature = "WCSessionUserInfoTransfer")]
187 /// 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.
188 ///
189 /// # Safety
190 ///
191 /// `user_info` generic should be of the correct type.
192 #[unsafe(method(transferUserInfo:))]
193 #[unsafe(method_family = none)]
194 pub unsafe fn transferUserInfo(
195 &self,
196 user_info: &NSDictionary<NSString, AnyObject>,
197 ) -> Retained<WCSessionUserInfoTransfer>;
198
199 #[cfg(feature = "WCSessionUserInfoTransfer")]
200 /// 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.
201 ///
202 /// # Safety
203 ///
204 /// `user_info` generic should be of the correct type.
205 #[unsafe(method(transferCurrentComplicationUserInfo:))]
206 #[unsafe(method_family = none)]
207 pub unsafe fn transferCurrentComplicationUserInfo(
208 &self,
209 user_info: &NSDictionary<NSString, AnyObject>,
210 ) -> Retained<WCSessionUserInfoTransfer>;
211
212 #[cfg(feature = "WCSessionUserInfoTransfer")]
213 /// 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).
214 #[unsafe(method(outstandingUserInfoTransfers))]
215 #[unsafe(method_family = none)]
216 pub unsafe fn outstandingUserInfoTransfers(
217 &self,
218 ) -> Retained<NSArray<WCSessionUserInfoTransfer>>;
219
220 #[cfg(feature = "WCSessionFile")]
221 /// 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.
222 ///
223 /// # Safety
224 ///
225 /// `metadata` generic should be of the correct type.
226 #[unsafe(method(transferFile:metadata:))]
227 #[unsafe(method_family = none)]
228 pub unsafe fn transferFile_metadata(
229 &self,
230 file: &NSURL,
231 metadata: Option<&NSDictionary<NSString, AnyObject>>,
232 ) -> Retained<WCSessionFileTransfer>;
233
234 #[cfg(feature = "WCSessionFile")]
235 /// Returns an array of file transfers that are still transferring (i.e. have not been cancelled, failed, or been received by the counterpart app).
236 #[unsafe(method(outstandingFileTransfers))]
237 #[unsafe(method_family = none)]
238 pub unsafe fn outstandingFileTransfers(&self) -> Retained<NSArray<WCSessionFileTransfer>>;
239 );
240}
241
242/// Methods declared on superclass `NSObject`.
243impl WCSession {
244 extern_methods!(
245 #[unsafe(method(new))]
246 #[unsafe(method_family = new)]
247 pub unsafe fn new() -> Retained<Self>;
248 );
249}
250
251extern_protocol!(
252 /// ----------------------------- WCSessionDelegate -----------------------------
253 /// The session calls the delegate methods when content is received and session
254 /// state changes. All delegate methods will be called on the same queue. The
255 /// delegate queue is a non-main serial queue. It is the client's responsibility
256 /// to dispatch to another queue if neccessary.
257 ///
258 /// See also [Apple's documentation](https://developer.apple.com/documentation/watchconnectivity/wcsessiondelegate?language=objc)
259 pub unsafe trait WCSessionDelegate: NSObjectProtocol {
260 /// Called when the session has completed activation. If session state is WCSessionActivationStateNotActivated there will be an error with more details.
261 #[unsafe(method(session:activationDidCompleteWithState:error:))]
262 #[unsafe(method_family = none)]
263 unsafe fn session_activationDidCompleteWithState_error(
264 &self,
265 session: &WCSession,
266 activation_state: WCSessionActivationState,
267 error: Option<&NSError>,
268 );
269
270 /// 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.
271 #[unsafe(method(sessionDidBecomeInactive:))]
272 #[unsafe(method_family = none)]
273 unsafe fn sessionDidBecomeInactive(&self, session: &WCSession);
274
275 /// 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.
276 #[unsafe(method(sessionDidDeactivate:))]
277 #[unsafe(method_family = none)]
278 unsafe fn sessionDidDeactivate(&self, session: &WCSession);
279
280 /// Called when any of the Watch state properties change.
281 #[optional]
282 #[unsafe(method(sessionWatchStateDidChange:))]
283 #[unsafe(method_family = none)]
284 unsafe fn sessionWatchStateDidChange(&self, session: &WCSession);
285
286 /// Called when the installed state of the Companion app changes.
287 #[optional]
288 #[unsafe(method(sessionCompanionAppInstalledDidChange:))]
289 #[unsafe(method_family = none)]
290 unsafe fn sessionCompanionAppInstalledDidChange(&self, session: &WCSession);
291
292 /// Called when the reachable state of the counterpart app changes. The receiver should check the reachable property on receiving this delegate callback.
293 #[optional]
294 #[unsafe(method(sessionReachabilityDidChange:))]
295 #[unsafe(method_family = none)]
296 unsafe fn sessionReachabilityDidChange(&self, session: &WCSession);
297
298 /// Called on the delegate of the receiver. Will be called on startup if the incoming message caused the receiver to launch.
299 ///
300 /// # Safety
301 ///
302 /// `message` generic should be of the correct type.
303 #[optional]
304 #[unsafe(method(session:didReceiveMessage:))]
305 #[unsafe(method_family = none)]
306 unsafe fn session_didReceiveMessage(
307 &self,
308 session: &WCSession,
309 message: &NSDictionary<NSString, AnyObject>,
310 );
311
312 #[cfg(feature = "block2")]
313 /// 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.
314 ///
315 /// # Safety
316 ///
317 /// `message` generic should be of the correct type.
318 #[optional]
319 #[unsafe(method(session:didReceiveMessage:replyHandler:))]
320 #[unsafe(method_family = none)]
321 unsafe fn session_didReceiveMessage_replyHandler(
322 &self,
323 session: &WCSession,
324 message: &NSDictionary<NSString, AnyObject>,
325 reply_handler: &block2::DynBlock<dyn Fn(NonNull<NSDictionary<NSString, AnyObject>>)>,
326 );
327
328 /// Called on the delegate of the receiver. Will be called on startup if the incoming message data caused the receiver to launch.
329 #[optional]
330 #[unsafe(method(session:didReceiveMessageData:))]
331 #[unsafe(method_family = none)]
332 unsafe fn session_didReceiveMessageData(&self, session: &WCSession, message_data: &NSData);
333
334 #[cfg(feature = "block2")]
335 /// 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.
336 #[optional]
337 #[unsafe(method(session:didReceiveMessageData:replyHandler:))]
338 #[unsafe(method_family = none)]
339 unsafe fn session_didReceiveMessageData_replyHandler(
340 &self,
341 session: &WCSession,
342 message_data: &NSData,
343 reply_handler: &block2::DynBlock<dyn Fn(NonNull<NSData>)>,
344 );
345
346 /// Called on the delegate of the receiver. Will be called on startup if an applicationContext is available.
347 ///
348 /// # Safety
349 ///
350 /// `application_context` generic should be of the correct type.
351 #[optional]
352 #[unsafe(method(session:didReceiveApplicationContext:))]
353 #[unsafe(method_family = none)]
354 unsafe fn session_didReceiveApplicationContext(
355 &self,
356 session: &WCSession,
357 application_context: &NSDictionary<NSString, AnyObject>,
358 );
359
360 #[cfg(feature = "WCSessionUserInfoTransfer")]
361 /// 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.
362 #[optional]
363 #[unsafe(method(session:didFinishUserInfoTransfer:error:))]
364 #[unsafe(method_family = none)]
365 unsafe fn session_didFinishUserInfoTransfer_error(
366 &self,
367 session: &WCSession,
368 user_info_transfer: &WCSessionUserInfoTransfer,
369 error: Option<&NSError>,
370 );
371
372 /// Called on the delegate of the receiver. Will be called on startup if the user info finished transferring when the receiver was not running.
373 ///
374 /// # Safety
375 ///
376 /// `user_info` generic should be of the correct type.
377 #[optional]
378 #[unsafe(method(session:didReceiveUserInfo:))]
379 #[unsafe(method_family = none)]
380 unsafe fn session_didReceiveUserInfo(
381 &self,
382 session: &WCSession,
383 user_info: &NSDictionary<NSString, AnyObject>,
384 );
385
386 #[cfg(feature = "WCSessionFile")]
387 /// 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.
388 #[optional]
389 #[unsafe(method(session:didFinishFileTransfer:error:))]
390 #[unsafe(method_family = none)]
391 unsafe fn session_didFinishFileTransfer_error(
392 &self,
393 session: &WCSession,
394 file_transfer: &WCSessionFileTransfer,
395 error: Option<&NSError>,
396 );
397
398 #[cfg(feature = "WCSessionFile")]
399 /// 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.
400 #[optional]
401 #[unsafe(method(session:didReceiveFile:))]
402 #[unsafe(method_family = none)]
403 unsafe fn session_didReceiveFile(&self, session: &WCSession, file: &WCSessionFile);
404 }
405);