跳到内容

iOS 消息送达跟踪

Pushwoosh 中有一个 API 方法,用于跟踪推送通知的送达情况。iOS 应用本身不支持此方法,因为 iOS 中的推送通知由操作系统处理,而非 Pushwoosh SDK。但是,您可以通过将用于推送送达跟踪的 Pushwoosh Notification Service Extension 添加到您的项目中来实现送达跟踪。您可以在这里找到为 iOS 应用实现消息送达跟踪的步骤。

添加 Notification Service Extension

Anchor link to
  1. 在 Xcode 中,选择 File > New > Target…

  2. 选择 Notification Service Extension 并按 Next

  1. 输入产品名称并按 Finish
  1. Activate scheme 提示中按 Cancel

通过取消,您可以让 Xcode 继续调试您的应用,而不是刚刚创建的扩展。如果您不小心激活了它,您可以在 Xcode 中切换回调试您的应用。

Notification Service Extension 的依赖项(仅限 CocoaPods)

Anchor link to

注意:如果您使用 Swift Package Manager 管理依赖项,可以跳过此步骤,因为依赖项会自动添加。

打开您的 Podfile 并为目标添加依赖项:

Podfile
target 'NotificationServiceExtension' do
use_frameworks!
pod 'PushwooshXCFramework'
end

在终端中运行以下命令以安装依赖项:

Terminal window
rm -rf Podfile.lock
pod deintegrate
pod setup
pod repo update
pod install

添加用于跟踪消息送达事件的代码

Anchor link to
  1. 将以下代码添加到您的 NotificationService.m 文件中:
import UserNotifications
import 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)
}
}
  1. Pushwoosh_APPID 添加到您的 Notification Service Extension info.plist 中。
<key>Pushwoosh_APPID</key>
<string>XXXXX-XXXXX</string>

与我们分享您的反馈

Anchor link to

您的反馈有助于我们创造更好的体验,因此如果您在 SDK 集成过程中遇到任何问题,我们非常希望听到您的声音。如果您遇到任何困难,请随时通过此表单与我们分享您的想法。