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