AMPAppMetricaPush 类

处理推送通知的主要类。

Instance methods

+downloadAttachmentsForNotificationRequest:

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

+handleApplicationDidFinishLaunchingWithOptions:

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

+handleDidReceiveNotificationRequest:

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

handleRemoteNotification:

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

+handleSceneWillConnectToSession:

处理从方法 scene:willConnectToSession:options: 打开的推送通知。

+isNotificationRelatedToSDK:

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

+setDeviceTokenFromData:

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

+setDeviceTokenFromData:pushEnvironment:

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

+setExtensionAppGroup:

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

+userDataForNotification:

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

Properties

userNotificationCenterDelegate

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

userNotificationCenterHandler

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

Method descriptions

+downloadAttachmentsForNotificationRequest:

+ (void)downloadAttachmentsForNotificationRequest:(UNNotificationRequest *)request
                                         callback:(AMPAttachmentsDownloadCallback)callback);

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

参数:

请求

UNNotificationRequest 的实例.

callback

上传附件的回调块。 Format:

typedef void (^AMPAttachmentsDownloadCallback) (NSArray<UNNotificationAttachment *> * _Nullable attachments, NSError * _Nullable error)

包括一个附件数组附件和一个错误,如果在上传文件时发生错误。

+handleApplicationDidFinishLaunchingWithOptions:

+ (void)handleApplicationDidFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions

处理来自方法 application:didFinishLaunchingWithOptions: 的推送通知打开事件。 Method should be invoked after AppMetrica SDK初始化。

参数:

launchOptions

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

+handleDidReceiveNotificationRequest:

+ (void)handleDidReceiveNotificationRequest:(UNNotificationRequest *)request

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

您应该在 didReceiveNotificationRequest:withContentHandler: 的实现中调用该方法。

参数:

请求

UNNotificationRequest 的实例.

+handleRemoteNotification:

+ (void)handleRemoteNotification:(NSDictionary *)userInfo

处理来自方法 application:didReceiveRemoteNotification:fetchCompletionHandler 的推送通知打开。 Method should be invoked after AppMetrica SDK初始化。

参数:

userInfo

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

+handleSceneWillConnectToSession:

+ (void)handleSceneWillConnectToSessionWithOptions:(UISceneConnectionOptions *)connectionOptions

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

参数:

connectionOptions

系统传输的 UISceneConnectionOptions 类对象,包含连接参数。

+isNotificationRelatedToSDK:

+ (BOOL)isNotificationRelatedToSDK:(NSDictionary *)userInfo;

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

参数:

userInfo

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

返回:

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

+setDeviceTokenFromData:

+ (void)setDeviceTokenFromData:(nullable NSData *)data

为应用的生产环境注册设备令牌。 Method should be invoked after AppMetrica SDK初始化。

参数:

数据

应用的设备令牌。

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

+setDeviceTokenFromData:pushEnvironment:

+ (void)setDeviceTokenFromData:(nullable NSData *)data
               pushEnvironment:(AMPAppMetricaPushEnvironment)pushEnvironment

将应用程序的设备令牌注册到指定环境中。 Method should be invoked after AppMetrica SDK初始化。

注意

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

参数:

数据

应用的设备令牌。

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

pushEnvironment

APNs 应用环境。

+setExtensionAppGroup:

+ (void)setExtensionAppGroup:(NSString *)appGroup

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

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

参数:

appGroup

共享App Groups组的名称。

+userDataForNotification:

+ (nullable NSString *)userDataForNotification:(NSDictionary *)userInfo

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

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

参数:

userInfo

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

返回:

任意数据字符串。

Property descriptions

+userNotificationCenterDelegate

@property (readonly, class) id<AMPUserNotificationCenterDelegate> userNotificationCenterDelegate;

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

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

[UNUserNotificationCenter currentNotificationCenter].delegate = [AMPAppMetricaPush userNotificationCenterDelegate];

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

+userNotificationCenterHandler

@property (readonly, class) id<AMPUserNotificationCenterHandling> userNotificationCenterHandler;

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

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

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