Notification Service Extension Use Instructions

Last updated: 2020-09-27 15:40:40


    To accurately count the message reach rate and receive rich media messages, the SDK provides the Service Extension API that can be called by the client to listen on message arrivals and receive rich media messages. You can follow the instructions below to use this feature.

    Creating Notification Extension Target

    1. In the Xcode menu bar, select File > New > Target.


      • The Bundle Id of the Project and Service must be different. The Service Bundle Id must be prefixed with the Project Bundle Id. For example, Project Bundle Id is com.tencent.tpns, and Service Bundle Id is com.tencent.tpns.service.
      • If the lowest version supported by the target of the primary project is below 10.0, set the extension target system version to v10.0.
      • If the lowest version supported by the target of the primary project is above 10.0, the extension target system version should be the same as the primary project target version.

    2. Enter the "Target" page, select Notification Service Extension, and click Next.

    3. Set "Product Name" and click Finish.

    Adding TPNS Extension Library (Two Methods)

    Method 1. Import through CocoaPods

    Download through Cocoapods:

    pod 'TPNS-iOS-Extension' 


    1. Create a Notification Service Extension target in Application Extension type, such as XXServiceExtension.
    2. Add the configuration item of XXServiceExtension in Podfile.

    Display effect after the configuration item is added in Podfile:

    target ‘XXServiceExtension'do
    pod 'TPNS-iOS-Extension' , '~>' 


    We recommend you use it together with pod 'TPNS-iOS' version or above.

    Method 2. Import manually

    Select the notification extension target and add the following dependent library files:

    • Add system libraries: libz.tbd, libsqlite3.tbd
    • Add the TPNS extension library: libXGExtension.a


    Calling SDK's statistics reporting API

    Report on the receipt of push messages. This API is used to track statistics of whether push messages reach devices.

     @brief   TPNS's processing of rich media notification and message arriving at device, i.e., message receipt
     @param request   Push request
     @param accessID   TPNS application `accessId`
     @param accessKey   TPNS application `accessKey`
     @param handler   Callback for message processing. The associated rich media file is processed in the callback method
    - (void)handleNotificationRequest:(nonnull UNNotificationRequest *)request
                               accessKey:(nonnull NSString *)accessKey
                       contentHandler:(nullable void (^)(NSArray<UNNotificationAttachment *> *_Nullable attachments, NSError *_Nullable error))handler;

    Sample code

    - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent *_Nonnull))contentHandler {
        self.contentHandler = contentHandler;
        self.bestAttemptContent = [request.content mutableCopy];
        /// For clusters outside Mainland China, please enable the corresponding cluster configuration (not required for clusters in Mainland China)
    //    [XGExtension defaultManager].reportDomainName = @""; /// Cluster in Hong Kong (China)
    //    [XGExtension defaultManager].reportDomainName = @"";  /// Cluster in Singapore
        [[XGExtension defaultManager] handleNotificationRequest:request accessID:<your accessID> accessKey:<your accessKey
            > contentHandler:^(NSArray<UNNotificationAttachment *> * _Nullable attachments, NSError * _Nullable error) {
            self.bestAttemptContent.attachments = attachments;

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback