SFMCNotificationService

Objective-C

@interface SFMCNotificationService : UNNotificationServiceExtension

Swift

class SFMCNotificationService : UNNotificationServiceExtension

The primary class for handling notification service extensions. SFMCNotificationService should be used as the base class for notification service extensions.

Note

Important: Do not implement any UNNotificationServiceExtension methods, including:
  • didReceive(_:withContentHandler:)
  • serviceExtensionTimeWillExpire()

Implementing these methods may interfere with the expected behavior of SFMCNotificationService, potentially leading to unexpected issues.

  • Override and implement this method to provide custom configuration option. The default implementation provides a logging level configruration option of .none - see: LogLevel.

    Declaration

    Objective-C

    - (nonnull SFMCNotificationServiceConfig *)sfmcProvideConfig;

    Swift

    func sfmcProvideConfig() -> SFMCNotificationServiceConfig
  • Processes incoming push notifications and allows custom modifications.

    Override this method to customize push notification handling, such as:

    • Enabling/Disabling logging and adjusting log levels.
    • Downloading and attaching media (images, videos) to the notification.
    • Adding custom key-value pairs to userInfo in the push payload.
    • Performing other necessary operations based on business requirements.

    Note

    Important Considerations:

    • Do not modify mutableContent.request.content.userInfo directly, as it may cause an exception. Instead, pass custom key-value pairs via contentHandler, e.g., contentHandler(@{@"customKey": @"customValue"}).

    • Limited execution time: The notification service extension has a restricted execution window, so keep your custom processing as short as possible.

    • Always call the completion handler in every possible execution path to avoid timeouts.

    Declaration

    Objective-C

    - (void)sfmcDidReceiveRequest:(nonnull UNNotificationRequest *)request
                   mutableContent:
                       (nonnull UNMutableNotificationContent *)mutableContent
               withContentHandler:
                   (nonnull void (^)(NSDictionary *_Nullable))contentHandler;

    Swift

    func sfmcDidReceive(_ request: UNNotificationRequest, mutableContent: UNMutableNotificationContent, withContentHandler contentHandler: @escaping ([AnyHashable : Any]?) -> Void)

    Parameters

    request

    The original notification request.

    mutableContent

    A mutable notification content object that can be modified.

    contentHandler

    A completion handler that must be called with the modified content.