AppMetricaPush 类

处理推送通知的主要类。

Instance methods

+downloadAttachmentsForNotificationRequest:

在推送通知中上传附件。 该方法适用于 iOS 10.0 及更高版本。

+handleApplicationDidFinishLaunchingWithOptions:

处理来自方法 application(_:didFinishLaunchingWithOptions:) 的推送通知打开事件。

+handleDidReceiveNotificationRequest:

处理来自通知服务扩展的推送通知接收。

+handleRemoteNotification:

处理来自方法 application(_:didReceiveRemoteNotification:fetchCompletionHandler:) 的推送通知打开。

+handleSceneWillConnectToSession:

处理来自方法 scene(_:willConnectTo:options:) 的推送通知打开事件。

+isNotificationRelatedToSDK:

Returns 是如果推送通知与AppMetrica相关。

+setDeviceTokenFromData:

为应用的生产环境注册设备令牌。

+setDeviceTokenFromData:pushEnvironment:

将应用程序的设备令牌注册到指定环境中。

+setExtensionAppGroup:

为应用和通知服务扩展注册共享的 App Groups。

+userDataForNotification:

返回在推送通知中传递的任意数据字符串。

Properties

userNotificationCenterDelegate

返回一个代理 UserNotificationCenterDelegate,用于处理 iOS 10 及更高版本的前台推送通知。

userNotificationCenterHandler

返回一个委托 UserNotificationCenterHandling,用于手动处理 iOS 10 及更高版本的前台推送通知。

Method descriptions

downloadAttachmentsForNotificationRequest:

class func downloadAttachments(request: UNNotificationRequest, callback: AttachmentsDownloadCallback)

在推送通知中上传附件。 该方法适用于 iOS 10.0 及更高版本。

参数:

请求

UNNotificationRequest 的实例。

callback

上传通知内容的回调块。 Format:

public typealias AttachmentsDownloadCallback = ([UNNotificationAttachment]?, Error?) -> Void`

包括一个附件数组,以及在上传文件时出现错误。

handleApplicationDidFinishLaunching(withOptions:)

class func handleApplicationDidFinishLaunching(withOptions launchOptions: [AnyHashable : Any]?)

处理来自方法 application (_: didFinishLaunchingWithOptions:) 的推送通知打开事件。 应在 AppMetrica SDK 初始化后调用此方法。

参数:

launchOptions

参数以“键-值”对的形式提供,包含有关应用程序启动的信息。

handleDidReceive(_:)

class func handleDidReceive(_ request: UNNotificationRequest?)

处理来自通知服务扩展的推送通知接收。

你应该在 didReceive (_: withContentHandler:) 的实现中调用该方法。

参数:

请求

UNNotificationRequest 的实例。

handleRemoteNotification(_:)

class func handleRemoteNotification(_ userInfo: [AnyHashable : Any]?)

处理来自方法 application(_:didReceiveRemoteNotification:fetchCompletionHandler:) 的推送通知打开。该方法应在 AppMetrica SDK 初始化后调用。

参数:

userInfo

推送通知的参数,以“键-值”对的形式由系统传输。

处理场景将连接到会话(使用:connectionOptions)

class func handleSceneWillConnectToSession(with: connectionOptions)

处理来自方法 scene(_:willConnectTo:options:) 的推送通知打开。 应在 AppMetrica SDK 初始化后调用此方法。

参数:

connectionOptions

系统传输的连接参数的 UIScene.ConnectionOptions 类对象。

isNotificationRelated(toSDK:)

class func isNotificationRelated(toSDK userInfo: [AnyHashable : Any]?) -> Bool

Returns 是如果推送通知与AppMetrica相关。

参数:

userInfo

推送通知的参数,以“键-值”对的形式由系统传输。

返回:

  • 是 — 如果推送通知与AppMetrica相关。
  • 否 — 如果推送通知与 AppMetrica 无关。

setDeviceTokenFrom(_:)

class func setDeviceTokenFrom(_ data: Data?)

为应用程序的生产环境注册设备令牌。 应在 AppMetrica SDK 初始化后调用此方法。

参数:

数据

应用程序的设备令牌。

如果你传递 nil 值,前一个设备令牌将被撤销。

setDeviceTokenFrom(_:pushEnvironment:)

class func setDeviceTokenFrom(_ data: Data?, pushEnvironment: AppMetricaPushEnvironment)

将应用程序的设备令牌注册到指定环境中。 应在 AppMetrica SDK 初始化后调用此方法。

注意

AppMetrica 允许您向 Sandbox APNs 发送推送通知。 但是,如果设备上运行了不同环境的应用版本(开发 和 生产),推送通知的处理可能会工作不正常。 为了避免这个问题,你可以为_开发_环境使用一个单独的测试 API 密钥。

参数:

数据

应用程序的设备令牌。

如果你传递 nil 值,前一个设备令牌将被撤销。

pushEnvironment

APNs 应用环境。

setExtensionAppGroup(_:)

class func setExtensionAppGroup(_ appGroup: String?)

为应用和通知服务扩展注册共享的 App Groups。

需要注册才能跟踪推送通知的送达。 要了解更多信息,请查看配置推送通知统计收集。

参数:

appGroup

共享App组的名称。

userData(forNotification:)

class func userData(forNotification userInfo: [AnyHashable : Any]?) -> String?

返回在推送通知中传递的任意数据字符串:

  • 在从 AppMetrica 界面发送时的 附加数据 字段中。
  • 在数据字段中发送时使用Push API。

参数:

userInfo

推送通知的参数,以“键值对”的形式由系统传输。

返回:

任意数据字符串。

Property descriptions

userNotificationCenterDelegate

var userNotificationCenterDelegate: UserNotificationCenterDelegate? { get }

返回一个代理 UserNotificationCenterDelegate,用于处理 iOS 10 及更高版本的前台推送通知。

要处理前台推送通知,请将此代码添加到 application(_:didFinishLaunchingWithOptions:) 方法中:

let delegate = AppMetricaPush.userNotificationCenterDelegate
UNUserNotificationCenter.current().delegate = delegate

要手动处理推送通知,请使用 userNotificationCenterHandler。

userNotificationCenterHandler

var userNotificationCenterHandler: UserNotificationCenterHandling? { get }

返回一个委托 UserNotificationCenterHandling,它允许你手动处理 iOS 10 及更高版本的前台推送通知。

使用此代理,如果你用自定义逻辑实现了UNUserNotificationCenterDelegate协议。 在这种情况下,您应该实现 UNUserNotificationCenterDelegate 代理的所有方法,并在 UserNotificationCenterHandling 中调用相应的方法。

为了简化推送通知处理,使用 userNotificationCenterDelegate。