Struct apple_bundle::entitlements::push_notifications::PushNotifications[][src]

pub struct PushNotifications {
    pub aps_environment: Option<APSEnvironment>,
    pub aps_environment_macos: Option<APSEnvironment>,
    pub usernotifications_filtering: Option<bool>,
}
Expand description

Push Notifications

Fields

aps_environment: Option<APSEnvironment>

The environment for push notifications.

This key specifies whether to use the development or production Apple Push Notification service (APNs) environment when registering for push notifications.

Xcode sets the value of the entitlement based on your app’s current provisioning profile. For example, if you’re using a development provisioning profile, Xcode sets the value to development. Production provisioning profile and Prerelease Versions and Beta Testers use production. These default settings can be modified. The development environment is also referred to as the sandbox environment.

Use this entitlement for both the UserNotifications and PushKit frameworks.

To add this entitlement to your app, enable the Push Notifications capability in Xcode.

Availability

  • iOS 10.0+
  • tvOS 10.0+
  • watchOS 3.0+

Framework

  • User Notifications
aps_environment_macos: Option<APSEnvironment>

The environment for push notifications in macOS apps.

This key specifies whether to use the development or production Apple Push Notification service (APNs) environment when registering for push notifications with registerForRemoteNotifications().

Xcode sets the value of the entitlement based on your app’s current provisioning profile. For example, if you’re using a development provisioning profile, Xcode sets the value to development.

To add this entitlement to your app, enable the Push Notifications capability in Xcode.

Availability

  • macOS 10.14+

Framework

  • User Notifications
usernotifications_filtering: Option<bool>

Enable receiving notifications without displaying the notification to the user.

This entitlement allows a notification service extension to receive remote notifications without displaying the notification to the user. To apply for this entitlement, see Request Notification Service Entitlement.

After you receive permission to use the entitlement, add com.apple.developer.usernotifications.filtering to the entitlements file in the Notification Service Extension target. This allows you to silence push notifications after your extension receives them.

Silence Push Notifications

To suppress a notification’s alert, create an empty UNNotificationContent object in your extension’s didReceive(_:withContentHandler:) method, and pass it to the content handler. Don’t specify a title, subtitle, body, attachments, or sound for the content.

override func didReceive(_ request: UNNotificationRequest, withContentHandler
contentHandler: @escaping (UNNotificationContent) -> Void) {

    // Determine whether you should suppress the notification.
    let suppress = myShouldSuppressNotification(request: request)
     
    if suppress {
        // Don't deliver the notification to the user.
        contentHandler(UNNotificationContent())
         
    } else {
        // Deliver the notification.
        guard let updatedContent = request.content.mutableCopy() as?
UNMutableNotificationContent else {             // This error should never
occur.             fatalError("Unable to create a mutable copy of the
content")         }
         
        // Update the notification's content, such as decrypting the body, here.
        contentHandler(updatedContent)
    }
}

Note

To silence a remote notification, you must set the apns-push-type header field to alert when you send the notification to the APNS server. Otherwise, the system always displays the notification banner to the user.

Availability

  • iOS 13.3+
  • macOS 11.0+

Framework

  • User Notifications

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.