apple_bundle/entitlements/
push_notifications.rs

1use serde::{Deserialize, Serialize};
2
3/// Push Notifications
4#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq)]
5pub struct PushNotifications {
6    /// The environment for push notifications.
7    ///
8    /// This key specifies whether to use the development or production Apple Push
9    /// Notification service (APNs) environment when registering for push notifications.
10    ///
11    /// Xcode sets the value of the entitlement based on your app's current provisioning
12    /// profile. For example, if you're using a development provisioning profile,
13    /// Xcode sets the value to development. Production provisioning profile and
14    /// Prerelease Versions and Beta Testers use production. These default settings
15    /// can be modified. The development environment is also referred to as the
16    /// sandbox environment.
17    ///
18    /// Use this entitlement for both the UserNotifications and PushKit frameworks.
19    ///
20    /// To add this entitlement to your app, enable the Push Notifications capability in
21    /// Xcode.
22    ///
23    /// ## Availability
24    /// * iOS 10.0+
25    /// * tvOS 10.0+
26    /// * watchOS 3.0+
27    ///
28    /// ## Framework
29    /// * User Notifications
30    #[serde(
31        rename = "aps-environment",
32        skip_serializing_if = "Option::is_none",
33        serialize_with = "crate::serialize_enum_option"
34    )]
35    pub aps_environment: Option<APSEnvironment>,
36    /// The environment for push notifications in macOS apps.
37    ///
38    /// This key specifies whether to use the development or production Apple Push
39    /// Notification service (APNs) environment when registering for push notifications
40    /// with registerForRemoteNotifications().
41    ///
42    /// Xcode sets the value of the entitlement based on your app's current provisioning
43    /// profile. For example, if you're using a development provisioning profile,
44    /// Xcode sets the value to development.
45    ///
46    /// To add this entitlement to your app, enable the Push Notifications capability in
47    /// Xcode.
48    ///
49    /// ## Availability
50    /// * macOS 10.14+
51    ///
52    /// ## Framework
53    /// * User Notifications
54    #[serde(
55        rename = "com.apple.developer.aps-environment",
56        skip_serializing_if = "Option::is_none",
57        serialize_with = "crate::serialize_enum_option"
58    )]
59    pub aps_environment_macos: Option<APSEnvironment>,
60    /// Enable receiving notifications without displaying the notification to the user.
61    ///
62    /// This entitlement allows a notification service extension to receive remote
63    /// notifications without displaying the notification to the user. To apply for
64    /// this entitlement, see Request Notification Service Entitlement.
65    ///
66    /// After you receive permission to use the entitlement, add
67    /// com.apple.developer.usernotifications.filtering to the entitlements file in the
68    /// Notification Service Extension target. This allows you to silence push
69    /// notifications after your extension receives them.
70    ///
71    /// ### Silence Push Notifications
72    /// To suppress a notification’s alert, create an empty UNNotificationContent object
73    /// in your extension’s didReceive(_:withContentHandler:) method, and pass it to the
74    /// content handler. Don’t specify a title, subtitle, body, attachments, or sound
75    /// for the content.
76    ///
77    /// ```swift
78    /// override func didReceive(_ request: UNNotificationRequest, withContentHandler
79    /// contentHandler: @escaping (UNNotificationContent) -> Void) {
80    ///
81    ///     // Determine whether you should suppress the notification.
82    ///     let suppress = myShouldSuppressNotification(request: request)
83    ///     
84    ///     if suppress {
85    ///         // Don't deliver the notification to the user.
86    ///         contentHandler(UNNotificationContent())
87    ///         
88    ///     } else {
89    ///         // Deliver the notification.
90    ///         guard let updatedContent = request.content.mutableCopy() as?
91    /// UNMutableNotificationContent else {             // This error should never
92    /// occur.             fatalError("Unable to create a mutable copy of the
93    /// content")         }
94    ///         
95    ///         // Update the notification's content, such as decrypting the body, here.
96    ///         contentHandler(updatedContent)
97    ///     }
98    /// }
99    /// ```
100    ///
101    /// ### Note
102    /// To silence a remote notification, you must set the apns-push-type header field to
103    /// alert when you send the notification to the APNS server. Otherwise, the system
104    /// always displays the notification banner to the user.
105    ///
106    /// ## Availability
107    /// * iOS 13.3+
108    /// * macOS 11.0+
109    ///
110    /// ## Framework
111    /// * User Notifications
112    #[serde(
113        rename = "com.apple.developer.usernotifications.filtering",
114        serialize_with = "crate::serialize_option",
115        skip_serializing_if = "Option::is_none"
116    )]
117    pub usernotifications_filtering: Option<bool>,
118}
119
120/// APS Environment
121#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
122pub enum APSEnvironment {
123    /// The APNs development environment.
124    #[serde(rename = "development")]
125    Development,
126    /// The APNs production environment.
127    #[serde(rename = "production")]
128    Production,
129}