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 use this feature in the following steps:
Note:
- The bundle ID of the primary project must be different from that of the service, and the latter must be prefixed with the former (for example, the former is
com.tencent.tpns
and the latter iscom.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 10.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.
Download through CocoaPods:
pod 'TPNS-iOS-Extension', '~> Version' // If the version is not specified, the latest version of the local pod TPNS-iOS-Extension will be downloaded.
Use instructions:
Notification Service Extension
target in Application Extension
type, such as XXServiceExtension
.XXServiceExtension
in the Podfile.target `XXServiceExtension'do
platform:ios,'10.0'
pod 'TPNS-iOS-Extension' , '~> Version' // The version must be consistent with the primary SDK (TPNS-iOS) version.
end
demo
> sdk
> XGPushStatistics
> extension
directory, and obtain the XGExtension.h
and libXGExtension.a
files.XGExtension.h
and libXGExtension.a
files obtained to the notification service extension target:libz.tbd
libXGExtension.a
After the integration, the directory structure is as follows:
To install new_tpns_svc_ext
for the first time, please run the following command in the terminal:
Associate the homebrew
repository of Tencent Push Notification Service.
brew tap tpns/serviceExtension https://github.com/TencentCloud/homebrew-tpnsServiceExtension.git
Install new_tpns_svc_ext
.
brew install new_tpns_svc_ext
Install the notification service extension plug-in for Tencent Push Notification Service.
new_tpns_svc_ext "AccessID" "AccessKey" "xxx.xcodeproj"
Parameter description:
AccessID
of your Tencent Push Notification Service product AccessKey
of your Tencent Push Notification Service product .xcodeproj
new_tpns_svc_ext "1600013400" "IWRNAHX6XXK6" "/Users/yanbiaomu/Developer/tencent/demo2/SDKToolObjcDemo2/SDKToolObjcDemo2.xcodeproj"
Note:To get
AccessID
andAccessKey
, go to the Tencent Push Notification Service console, choose Product Management, and click Configuration Management in the record of a target product. Then you can findAccessID
andAccessKey
on the page displayed.
new_tpns_svc_ext
command to verify the result.new_tpns_svc_ext
command is run in the terminal, the notification extension plugin is successfully integrated. TPNS service auto coding done!
New TPNSService Extension Success
new_tpns_svc_ext
When a new version of the SDK notification extension plugin is released, you can run the following command in the terminal for upgrade:
brew update && brew reinstall new_tpns_svc_ext
Note:
- You can view the release notes of the latest version in SDK for iOS.
- Currently, the HomeBrew command
new_tpns_svc_ext
supports integrating only the notification service extension pluginTPNSService
but not basic push capabilities.
NotificationService
into the notification extension class XGExtension.h
.didReceiveNotificationRequest:withContentHandler
:/**
@brief //Tencent Push Notification Service processes rich media notifications and device-reached messages, that is, message receipts.
@param request //Push request
@param accessID //Tencent Push Notification Service application `AccessID`
@param accessKey //Tencent Push Notification Service application `AccessKey`
@param handler //Callback of processing messages. Process the associated rich media file in the callback method.
*/
accessID:(uint32_t)accessID
accessKey:(nonnull NSString *)accessKey
contentHandler:(nullable <span class="hljs-keyword">void</span> (^)(NSArray<UNNotificationAttachment *> *_Nullable attachments, NSError *_Nullable <span class="hljs-keyword">error</span>))<span class="hljs-keyword">handler</span>;
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent *_Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
/// For clusters outside Guangzhou, please enable the corresponding cluster configuration (not required for clusters in Guangzhou)
// [XGExtension defaultManager].reportDomainName = @"tpns.hk.tencent.com"; /// Cluster in Hong Kong (China)
// [XGExtension defaultManager].reportDomainName = @"tpns.sgp.tencent.com"; /// Cluster in Singapore
// [XGExtension defaultManager].reportDomainName = @"tpns.sh.tencent.com"; /// Cluster in Shanghai
[[XGExtension defaultManager] handleNotificationRequest:request accessID:<your accessID> accessKey:<your accessKey
> contentHandler:^(NSArray<UNNotificationAttachment *> * _Nullable attachments, NSError * _Nullable error) {
self.bestAttemptContent.attachments = attachments;
self.contentHandler(self.bestAttemptContent); // If you need to add business logic before the notification pops up, add it before calling ContentHandler.
}];
}
After completing the integration as instructed above, you can verify whether the extension plugin is successfully integrated in the following steps:
If the device receives the pushed message but there is no arrival data, troubleshoot as follows:
UNNotificationServiceExtension
to the primary target by PID
or Name
.mutable-content
field in the notification content must be 1
(since Tencent Push Notification Service SDK v1.2.8.0, the APNs channel is used by default in the background, and the Tencent Push Notification Service channel is used in the foreground. To debug the notification service extension plugin, you need to make the application run in the background). If the breakpoints are executed, the debugging is successful. Otherwise, stop all targets and start over from step 1.The notification service extension plugin must be integrated for client arrival reporting. If no arrival data is reported after integration, check whether AccessID
and AccessKey
of the primary project are consistent with those of the notification service extension plugin and whether the mutable-content
field in the notification content in the web console or RESTful API is 1
.
Only when the two conditions checked are met, the notification service extension plugin on the client will be run, and arrival data will be reported.
Was this page helpful?