iOS 消息送达跟踪
Pushwoosh 中有一个 API 方法,用于跟踪推送通知的送达情况。iOS 应用本身不支持此方法,因为 iOS 中的推送通知由操作系统处理,而非 Pushwoosh SDK。但是,您可以通过将用于推送送达跟踪的 Pushwoosh Notification Service Extension 添加到您的项目中来实现送达跟踪。您可以在这里找到为 iOS 应用实现消息送达跟踪的步骤。
添加 Notification Service Extension
Anchor link to-
在 Xcode 中,选择 File > New > Target…
-
选择 Notification Service Extension 并按 Next。
- 输入产品名称并按 Finish。
- 在 Activate scheme 提示中按 Cancel。
通过取消,您可以让 Xcode 继续调试您的应用,而不是刚刚创建的扩展。如果您不小心激活了它,您可以在 Xcode 中切换回调试您的应用。
Notification Service Extension 的依赖项(仅限 CocoaPods)
Anchor link to注意:如果您使用 Swift Package Manager 管理依赖项,可以跳过此步骤,因为依赖项会自动添加。
打开您的 Podfile 并为目标添加依赖项:
target 'NotificationServiceExtension' do use_frameworks! pod 'PushwooshXCFramework'end在终端中运行以下命令以安装依赖项:
rm -rf Podfile.lockpod deintegratepod setuppod repo updatepod install添加用于跟踪消息送达事件的代码
Anchor link to- 将以下代码添加到您的 NotificationService.m 文件中:
import UserNotificationsimport PushwooshFramework
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)? var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { PWNotificationExtensionManager.shared().handle(request, contentHandler: contentHandler) }}#import "PWNotificationExtensionManager.h"
@interface NotificationService : UNNotificationServiceExtension
@end
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { [[PWNotificationExtensionManager sharedManager] handleNotificationRequest:request contentHandler:contentHandler];}
- (void)serviceExtensionTimeWillExpire { // Called just before the extension is terminated by the system. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.}
@end- 将 Pushwoosh_APPID 添加到您的 Notification Service Extension info.plist 中。
<key>Pushwoosh_APPID</key> <string>XXXXX-XXXXX</string>与我们分享您的反馈
Anchor link to您的反馈有助于我们创造更好的体验,因此如果您在 SDK 集成过程中遇到任何问题,我们非常希望听到您的声音。如果您遇到任何困难,请随时通过此表单与我们分享您的想法。