objc2_push_kit/generated/PKPushRegistry.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "dispatch2")]
6use dispatch2::*;
7use objc2::__framework_prelude::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12extern "C" {
13 /// A push type for Voice-over-IP (VoIP) call invitations.
14 ///
15 /// Use this type of notification to initiate live voice calls over the network.
16 /// Apps receiving VoIP push notifications must report the call quickly to
17 /// CallKit, so it can alert the user to the presence of the incoming call. For
18 /// apps linked against the iOS 13 SDK or later, the system terminates your app
19 /// if you fail to report these notifications to CallKit. If your app repeatedly
20 /// fails to report VoIP notifications to CallKit, the system stops launching
21 /// your app for VoIP push notifications.
22 ///
23 /// Don't use this type of notification for anything other than initiating VoIP
24 /// calls. If you don't want to post the CallKit call interface, handle
25 /// notifications with the
26 /// <doc
27 /// ://com.apple.documentation/documentation/usernotifications> framework
28 /// instead of ``PushKit``. When sending encrypted content, use a Notification
29 /// Service Extension to decrypt that content before displaying it to the user.
30 /// You can also use a Notification Content Extension to display a custom
31 /// interface for your app's notifications. For more information, see
32 /// <doc
33 /// ://com.apple.documentation/documentation/usernotifications/modifying_content_in_newly_delivered_notifications>
34 /// and
35 /// <doc
36 /// ://com.apple.documentation/documentation/usernotificationsui/customizing_the_appearance_of_notifications>.
37 ///
38 /// See also [Apple's documentation](https://developer.apple.com/documentation/pushkit/pkpushtypevoip?language=objc)
39 #[cfg(feature = "PKDefines")]
40 pub static PKPushTypeVoIP: &'static PKPushType;
41}
42
43extern "C" {
44 /// A push type for watchOS complications.
45 ///
46 /// Use this type of notification to deliver updated data related for your
47 /// watchOS app’s complication. The watchOS app’s complication must be active on
48 /// the user’s current clock face. If it is not, the system does not deliver
49 /// pushes of this type. For watchOS 6 and later, send the push notification
50 /// directly to Apple Watch. For watchOS 5 and earlier, you must send it to the
51 /// iOS companion instead.
52 ///
53 /// The time your watchOS app spends processing these push notifications counts
54 /// against the budget allotted to your complication for updating itself. Don't
55 /// start any long-running tasks when processing the notification payload. In
56 /// fact, it is recommended that you include all needed data in the payload so
57 /// that your app can process that data quickly.
58 ///
59 /// The system limits you to 50 push notifications per day. If you exceed the
60 /// limit, subsequent pushes are not delivered.
61 ///
62 /// See also [Apple's documentation](https://developer.apple.com/documentation/pushkit/pkpushtypecomplication?language=objc)
63 #[cfg(feature = "PKDefines")]
64 #[deprecated = "Complication pushes are supported directly on watchOS now, so this should no longer be used on iOS."]
65 pub static PKPushTypeComplication: &'static PKPushType;
66}
67
68extern "C" {
69 /// A push type for file provider updates.
70 ///
71 /// Use file provider notifications to update your File Provider extension's content
72 /// from your server. For more information, see
73 /// <doc
74 /// ://com.apple.documentation/documentation/fileprovider/nonreplicated_file_provider_extension/content_and_change_tracking/tracking_your_file_provider_s_changes>.
75 ///
76 /// See also [Apple's documentation](https://developer.apple.com/documentation/pushkit/pkpushtypefileprovider?language=objc)
77 #[cfg(feature = "PKDefines")]
78 pub static PKPushTypeFileProvider: &'static PKPushType;
79}
80
81extern_class!(
82 /// An object that requests the delivery and handles the receipt of PushKit notifications.
83 ///
84 /// A `PKPushRegistry` object manages only certain types of notifications,
85 /// such as high-priority notifications needed by a VoIP app. PushKit wakes up your app
86 /// as needed to deliver incoming notifications and delivers the notifications directly
87 /// to the push registry object that requested them.
88 ///
89 /// Every time your app launches, whether in the foreground or in the background, create
90 /// a push registry object and configure it. Typically, you keep the push registry object
91 /// running for the duration of your app. Each push registry object delivers incoming
92 /// notifications to its ``PushKit/PKPushRegistry/delegate`` object, which also handles
93 /// the responses for registration requests. The listing below shows how to create
94 /// a push registry object and request VoIP notifications. Always assign an appropriate
95 /// delegate object before modifying the ``PushKit/PKPushRegistry/desiredPushTypes``
96 /// property.
97 ///
98 /// ```objc
99 /// - (void) registerForVoIPPushes {
100 /// self.voipRegistry = [[PKPushRegistry alloc] initWithQueue:nil];
101 /// self.voipRegistry.delegate = self;
102 ///
103 /// // Initiate registration.
104 /// self.voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
105 /// }
106 /// ```
107 ///
108 /// Assigning a new value to the ``PushKit/PKPushRegistry/desiredPushTypes`` property
109 /// registers the push registry object with the PushKit servers. The server reports the
110 /// success or failure of your registration attempts asynchronously to the push registry,
111 /// which then reports those results to its delegate object. The push registry also delivers
112 /// all received notifications to the delegate object. For more information about the
113 /// delegate methods, see ``PushKit/PKPushRegistryDelegate``.
114 ///
115 /// ## Topics
116 ///
117 /// ### Initializing a Push Registry
118 ///
119 /// - ``PushKit/PKPushRegistry/initWithQueue:``
120 ///
121 /// ### Receiving the Notification Data
122 ///
123 /// - ``PushKit/PKPushRegistry/delegate``
124 /// - ``PushKit/PKPushRegistryDelegate``
125 ///
126 /// ### Managing the Push Registry
127 ///
128 /// - ``PushKit/PKPushRegistry/desiredPushTypes``
129 /// - ``PushKit/PKPushRegistry/pushTokenForType:``
130 ///
131 /// See also [Apple's documentation](https://developer.apple.com/documentation/pushkit/pkpushregistry?language=objc)
132 #[unsafe(super(NSObject))]
133 #[derive(Debug, PartialEq, Eq, Hash)]
134 pub struct PKPushRegistry;
135);
136
137extern_conformance!(
138 unsafe impl NSObjectProtocol for PKPushRegistry {}
139);
140
141impl PKPushRegistry {
142 extern_methods!(
143 /// The delegate object that receives notifications coming from the push registry object.
144 ///
145 /// You must assign a valid object to this property before modifying the ``PushKit/PKPushRegistry/desiredPushTypes``
146 /// property. A valid delegate object is required to receive push tokens and payload
147 /// data from incoming pushes.
148 ///
149 /// For more information about the methods of the `PKPushRegistryDelegate`
150 /// protocol, see ``PushKit/PKPushRegistryDelegate``.
151 #[unsafe(method(delegate))]
152 #[unsafe(method_family = none)]
153 pub unsafe fn delegate(
154 &self,
155 ) -> Option<Retained<ProtocolObject<dyn PKPushRegistryDelegate>>>;
156
157 /// Setter for [`delegate`][Self::delegate].
158 ///
159 /// This is a [weak property][objc2::topics::weak_property].
160 #[unsafe(method(setDelegate:))]
161 #[unsafe(method_family = none)]
162 pub unsafe fn setDelegate(
163 &self,
164 delegate: Option<&ProtocolObject<dyn PKPushRegistryDelegate>>,
165 );
166
167 #[cfg(feature = "PKDefines")]
168 /// Registers the push types for this push registry object.
169 ///
170 /// When you assign a value to this property, the push registry object makes a registration
171 /// request with the PushKit server. This request is asynchronous, and the success or
172 /// failure of the request is reported to your registery's delegate object. For a successful
173 /// registration, PushKit delivers a push token to the delegate. Use that token to generate
174 /// push requests from your server.
175 ///
176 /// For a list of push types that you may include in the set, see ``PushKit/PKPushType``.
177 #[unsafe(method(desiredPushTypes))]
178 #[unsafe(method_family = none)]
179 pub unsafe fn desiredPushTypes(&self) -> Option<Retained<NSSet<PKPushType>>>;
180
181 #[cfg(feature = "PKDefines")]
182 /// Setter for [`desiredPushTypes`][Self::desiredPushTypes].
183 ///
184 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
185 #[unsafe(method(setDesiredPushTypes:))]
186 #[unsafe(method_family = none)]
187 pub unsafe fn setDesiredPushTypes(&self, desired_push_types: Option<&NSSet<PKPushType>>);
188
189 #[cfg(feature = "PKDefines")]
190 /// Retrieves the locally cached push token for the specified push type.
191 ///
192 /// If registration for a specific push type is successful, the push registry delivers
193 /// the corresponding push token to its delegate and adds a copy of the token to its
194 /// local cache. Use this method to retrieve the token at a later time.
195 ///
196 /// - Parameters:
197 /// - type: A push type requested by this push registry object. For a list of possible types,
198 /// see ``PushKit/PKPushType``.
199 ///
200 /// - Returns: The push token used to send pushes to the device or `nil` if no token is available
201 /// for the specified type.
202 #[unsafe(method(pushTokenForType:))]
203 #[unsafe(method_family = none)]
204 pub unsafe fn pushTokenForType(&self, r#type: &PKPushType) -> Option<Retained<NSData>>;
205
206 #[cfg(feature = "dispatch2")]
207 /// Creates a push registry with the specified dispatch queue.
208 ///
209 /// - Parameters:
210 /// - queue: The dispatch queue on which to execute the delegate methods. It is recommended that
211 /// you specify a serial queue for this parameter. Specify `nil` to execute the delegate
212 /// methods on the app’s main queue.
213 ///
214 /// - Returns: A `PKPushRegistry` object that you can use to register for push tokens and use to
215 /// receive notifications.
216 ///
217 /// # Safety
218 ///
219 /// `queue` possibly has additional threading requirements.
220 #[unsafe(method(initWithQueue:))]
221 #[unsafe(method_family = init)]
222 pub unsafe fn initWithQueue(
223 this: Allocated<Self>,
224 queue: Option<&DispatchQueue>,
225 ) -> Retained<Self>;
226
227 /// Unavailable, use -initWithQueue: instead.
228 #[unsafe(method(init))]
229 #[unsafe(method_family = init)]
230 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
231 );
232}
233
234/// Methods declared on superclass `NSObject`.
235impl PKPushRegistry {
236 extern_methods!(
237 #[unsafe(method(new))]
238 #[unsafe(method_family = new)]
239 pub unsafe fn new() -> Retained<Self>;
240 );
241}
242
243extern_protocol!(
244 /// The methods that you use to handle incoming PushKit notifications and registration
245 /// events.
246 ///
247 /// Implement the methods of this protocol in an object of your app and assign that object
248 /// to the ``PushKit/PKPushRegistry/delegate`` property of your `PKPushRegistry`
249 /// object. Use the methods of this protocol to process incoming notifications and to
250 /// react to token registration and invalidation.
251 ///
252 /// ## Topics
253 ///
254 /// ### Responding to Registration Events
255 ///
256 /// - ``PushKit/PKPushRegistryDelegate/pushRegistry:didUpdatePushCredentials:forType:``
257 /// - ``PushKit/PKPushRegistryDelegate/pushRegistry:didInvalidatePushTokenForType:``
258 ///
259 /// ### Handling an Incoming Notification
260 ///
261 /// - ``PushKit/PKPushRegistryDelegate/pushRegistry:didReceiveIncomingPushWithPayload:forType:withCompletionHandler:``
262 ///
263 /// ### Deprecated Methods
264 ///
265 /// - ``PushKit/PKPushRegistryDelegate/pushRegistry:didReceiveIncomingPushWithPayload:forType:``
266 ///
267 /// See also [Apple's documentation](https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate?language=objc)
268 pub unsafe trait PKPushRegistryDelegate: NSObjectProtocol {
269 #[cfg(all(feature = "PKDefines", feature = "PKPushCredentials"))]
270 /// Tells the delegate that the system updated the credentials for the specified type
271 /// of push notification.
272 ///
273 /// The system calls this method when it receives new credentials (including a push token)
274 /// for the specified push type.
275 ///
276 /// - Parameters:
277 /// - registry: The ``PushKit/PKPushRegistry`` instance responsible for the delegate callback.
278 /// - credentials: The push credentials that can be used to send pushes to the device for the specified push type.
279 /// - type: One of the requested notification types. This type is present in the ``PushKit/PKPushRegistry/desiredPushTypes`` property of the push registry.
280 #[unsafe(method(pushRegistry:didUpdatePushCredentials:forType:))]
281 #[unsafe(method_family = none)]
282 unsafe fn pushRegistry_didUpdatePushCredentials_forType(
283 &self,
284 registry: &PKPushRegistry,
285 push_credentials: &PKPushCredentials,
286 r#type: &PKPushType,
287 );
288
289 #[cfg(all(feature = "PKDefines", feature = "PKPushPayload"))]
290 /// Notifies the delegate that a remote push has been received.
291 ///
292 /// This method is invoked when a push notification has been received for the
293 /// specified push type.
294 ///
295 /// - Parameters:
296 /// - registry: The ``PKPushRegistry`` instance responsible for the delegate callback.
297 /// - payload: The push payload sent by a developer via APNS server API.
298 /// - type: This is a ``PushKit/PKPushType`` constant, which is present in `[registry desiredPushTypes]`.
299 #[deprecated]
300 #[optional]
301 #[unsafe(method(pushRegistry:didReceiveIncomingPushWithPayload:forType:))]
302 #[unsafe(method_family = none)]
303 unsafe fn pushRegistry_didReceiveIncomingPushWithPayload_forType(
304 &self,
305 registry: &PKPushRegistry,
306 payload: &PKPushPayload,
307 r#type: &PKPushType,
308 );
309
310 #[cfg(all(feature = "PKDefines", feature = "PKPushPayload", feature = "block2"))]
311 /// Tells the delegate that a remote push notification arrived.
312 ///
313 /// The system calls this method when it receives a push notification for the specified
314 /// push type. Use this method to extract data from the notification's payload and to
315 /// perform the relevant task for that data. For example, use this method to update the
316 /// complication data of your watchOS app. When you finish the task, execute the provided
317 /// `completion` handler block to let PushKit know you are finished.
318 ///
319 /// When linking against the iOS 13 SDK or later, your implementation of this method
320 /// must report notifications of type ``PushKit/PKPushTypeVoIP`` to the
321 /// <doc
322 /// ://com.apple.documentation/documentation/callkit>
323 /// framework by calling the
324 /// <doc
325 /// ://com.apple.documentation/documentation/callkit/cxprovider/1930694-reportnewincomingcallwithuuid>
326 /// method of your app's
327 /// <doc
328 /// ://com.apple.documentation/documentation/callkit/cxprovider>
329 /// object. When you call that method, the system displays the standard incoming call
330 /// interface to the user unless an error occurs. For example, the system reports an
331 /// error if the user enabled Do Not Disturb. You may establish a connection to your
332 /// VoIP server in tandem with notify CallKit.
333 ///
334 /// > Important: On iOS 13.0 and later, if you fail to report a call to CallKit, the
335 /// system will terminate your app. Repeatedly failing to report calls may cause the
336 /// system to stop delivering any more VoIP push notifications to your app. If you want
337 /// to initiate a VoIP call without using CallKit,
338 /// register for push notifications using the User Notifications
339 /// framework instead of PushKit. For more information, see
340 /// <doc
341 /// ://com.apple.documentation/documentation/usernotifications>.
342 ///
343 /// - Parameters:
344 /// - registry: The ``PushKit/PKPushRegistry`` instance responsible for the delegate callback.
345 /// - payload: The push payload sent by a developer via APNs server API.
346 /// - type: This is a ``PushKit/PKPushType`` constant, which is present in `[registry desiredPushTypes]`.
347 /// - completion: The notification's completion handler. Execute this block when you finish processing the notification.
348 #[optional]
349 #[unsafe(method(pushRegistry:didReceiveIncomingPushWithPayload:forType:withCompletionHandler:))]
350 #[unsafe(method_family = none)]
351 unsafe fn pushRegistry_didReceiveIncomingPushWithPayload_forType_withCompletionHandler(
352 &self,
353 registry: &PKPushRegistry,
354 payload: &PKPushPayload,
355 r#type: &PKPushType,
356 completion: &block2::DynBlock<dyn Fn()>,
357 );
358
359 #[cfg(feature = "PKDefines")]
360 /// Tells the delegate that the system invalidated the push token for the specified type.
361 ///
362 /// The system calls this method when a previously provided push token is no longer valid
363 /// for use. No action is necessary on your part to reregister the push type. Instead,
364 /// use this method to notify your server not to send push notifications using the matching
365 /// push token.
366 ///
367 /// - Parameters:
368 /// - registry: The ``PushKit/PKPushRegistry`` instance responsible for the delegate callback.
369 /// - type: This is a ``PushKit/PKPushType`` constant, which is present in `[registry desiredPushTypes]`.
370 #[optional]
371 #[unsafe(method(pushRegistry:didInvalidatePushTokenForType:))]
372 #[unsafe(method_family = none)]
373 unsafe fn pushRegistry_didInvalidatePushTokenForType(
374 &self,
375 registry: &PKPushRegistry,
376 r#type: &PKPushType,
377 );
378 }
379);