YMPYandexMetricaPush class

The main class for push notifications handling.

Instance methods

+downloadAttachmentsForNotificationRequest:

Uploads attached files in push notifications. The method is available for iOS 10.0 and higher.

+handleApplicationDidFinishLaunchingWithOptions:

Handles push notification openings from the method application (_: didFinishLaunchingWithOptions:). Method should be invoked after AppMetrica SDK initialization.

+handleDidReceiveNotificationRequest:

Handles push notifications receiving from Notification Service Extension.

+handleRemoteNotification:

Handles push notification openings from the method application(_:didReceiveRemoteNotification:fetchCompletionHandler:) Method should be invoked after AppMetrica SDK initialization.

+handleSceneWillConnectToSession:

Handles push notification openings from the method scene(_:willConnectTo:options:). Method should be invoked after AppMetrica SDK initialization.

+isNotificationRelatedToSDK:

Returns YES if a push notification is related to AppMetrica.

+setDeviceTokenFromData:

Registers the device token for an application with a production environment. Method should be invoked after AppMetrica SDK initialization.

+setDeviceTokenFromData:pushEnvironment:

Registers the device token of the application with the specified environment. Method should be invoked after AppMetrica SDK initialization.

+setExtensionAppGroup:

Registers the App Groups shared group for the app and Notification Service Extension.

+userDataForNotification:
Returns an arbitrary data string that is passed in the push notification:
  • In the Additional data field when sending from the AppMetrica interface.
  • In the data field when sending using the Push API.
+userNotificationCenterDelegate:

Returns a delegate YMPUserNotificationCenterDelegate, which handles foreground push notifications on iOS 10 and higher.

+userNotificationCenterHandler:

Returns a delegate YMPUserNotificationCenterHandling, which allows you to manually handle foreground push notifications on iOS 10 and higher.

+downloadAttachmentsForNotificationRequest:

Uploads attached files in push notifications. The method is available for iOS 10.0 and higher.

+handleApplicationDidFinishLaunchingWithOptions:

Handles push notification openings from the method application (_: didFinishLaunchingWithOptions:). Method should be invoked after AppMetrica SDK initialization.

+handleDidReceiveNotificationRequest:

Handles push notifications receiving from Notification Service Extension.

+handleRemoteNotification:

Handles push notification openings from the method application(_:didReceiveRemoteNotification:fetchCompletionHandler:) Method should be invoked after AppMetrica SDK initialization.

+handleSceneWillConnectToSession:

Handles push notification openings from the method scene(_:willConnectTo:options:). Method should be invoked after AppMetrica SDK initialization.

+isNotificationRelatedToSDK:

Returns YES if a push notification is related to AppMetrica.

+setDeviceTokenFromData:

Registers the device token for an application with a production environment. Method should be invoked after AppMetrica SDK initialization.

+setDeviceTokenFromData:pushEnvironment:

Registers the device token of the application with the specified environment. Method should be invoked after AppMetrica SDK initialization.

+setExtensionAppGroup:

Registers the App Groups shared group for the app and Notification Service Extension.

+userDataForNotification:
Returns an arbitrary data string that is passed in the push notification:
  • In the Additional data field when sending from the AppMetrica interface.
  • In the data field when sending using the Push API.
+userNotificationCenterDelegate:

Returns a delegate YMPUserNotificationCenterDelegate, which handles foreground push notifications on iOS 10 and higher.

+userNotificationCenterHandler:

Returns a delegate YMPUserNotificationCenterHandling, which allows you to manually handle foreground push notifications on iOS 10 and higher.

Method descriptions

downloadAttachmentsForNotificationRequest:

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

Uploads attached files in push notifications. The method is available for iOS 10.0 and higher.

Parameters:
request

The instance of UNNotificationRequest.

callback

The callback block for uploading notification contents. Format: public typealias YMPAttachmentsDownloadCallback = ([UNNotificationAttachment]?, Error?) -> Void. Includes an array of attachments and an error if an error occurs when uploading files.

request

The instance of UNNotificationRequest.

callback

The callback block for uploading notification contents. Format: public typealias YMPAttachmentsDownloadCallback = ([UNNotificationAttachment]?, Error?) -> Void. Includes an array of attachments and an error if an error occurs when uploading files.

handleApplicationDidFinishLaunching(withOptions:)

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

Handles push notification openings from the method application (_: didFinishLaunchingWithOptions:). Method should be invoked after AppMetrica SDK initialization.

Parameters:
launchOptions

Parameters as key-value pairs that contain information about the application start.

launchOptions

Parameters as key-value pairs that contain information about the application start.

handleDidReceive(_:)

class func handleDidReceive(_ request: UNNotificationRequest?)

Handles push notifications receiving from Notification Service Extension.

You should call the method in the implementation of didReceive (_: withContentHandler:).

Parameters:
request

The instance of UNNotificationRequest.

request

The instance of UNNotificationRequest.

handleRemoteNotification(_:)

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

Handles push notification openings from the method application(_:didReceiveRemoteNotification:fetchCompletionHandler:) Method should be invoked after AppMetrica SDK initialization.

Parameters:
userInfo

Parameters of push notifications as key-value pairs that are transmitted by the system.

userInfo

Parameters of push notifications as key-value pairs that are transmitted by the system.

handleSceneWillConnectToSession(with: connectionOptions)

class func handleSceneWillConnectToSession(with: connectionOptions)

Handles push notification openings from the method scene(_:willConnectTo:options:). Method should be invoked after AppMetrica SDK initialization.

Parameters:
connectionOptions

The UIScene.ConnectionOptions class object with connection parameters that are transmitted by the system.

connectionOptions

The UIScene.ConnectionOptions class object with connection parameters that are transmitted by the system.

isNotificationRelated(toSDK:)

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

Returns YES if a push notification is related to AppMetrica.

Parameters:
userInfo

Parameters of push notifications as key-value pairs that are transmitted by the system.

userInfo

Parameters of push notifications as key-value pairs that are transmitted by the system.

Returns:

  • YES — If the push notification refers to AppMetrica.
  • NO — If the push notification is not related to AppMetrica.

setDeviceTokenFrom(_:)

class func setDeviceTokenFrom(_ data: Data?)

Registers the device token for an application with a production environment. Method should be invoked after AppMetrica SDK initialization.

Parameters:
data

Device token of the application.

If you pass the nil value, the previous device token is revoked.

data

Device token of the application.

If you pass the nil value, the previous device token is revoked.

setDeviceTokenFrom(_:pushEnvironment:)

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

Registers the device token of the application with the specified environment. Method should be invoked after AppMetrica SDK initialization.

Attention. AppMetrica allows you to send push notifications to Sandbox APNs. However, push notification processing may not work correctly if versions of the application with different environments were run on the device(development and production). To avoid this issue, you can use a separate test API key for development environment.
Parameters:
data

Device token of the application.

If you pass the nil value, the previous device token is revoked.

pushEnvironment

APNs app environment.

data

Device token of the application.

If you pass the nil value, the previous device token is revoked.

pushEnvironment

APNs app environment.

setExtensionAppGroup(_:)

class func setExtensionAppGroup(_ appGroup: String?)

Registers the App Groups shared group for the app and Notification Service Extension.

Registration is necessary for tracking the delivery of push notifications. For more information, see Configuring statistics collection for push notifications.

Parameters:
appGroup

The name of the shared App Groups group.

appGroup

The name of the shared App Groups group.

userData(forNotification:)

class func userData(forNotification userInfo: [AnyHashable : Any]?) -> String?
Returns an arbitrary data string that is passed in the push notification:
  • In the Additional data field when sending from the AppMetrica interface.
  • In the data field when sending using the Push API.
Parameters:
userInfo

Parameters of push notifications as key-value pairs that are transmitted by the system.

userInfo

Parameters of push notifications as key-value pairs that are transmitted by the system.

Returns:

An arbitrary data string.

userNotificationCenterDelegate()

class func userNotificationCenterDelegate() -> YMPUserNotificationCenterDelegate?

Returns a delegate YMPUserNotificationCenterDelegate, which handles foreground push notifications on iOS 10 and higher.

To handle foreground push notifications, add this code to the application(_:didFinishLaunchingWithOptions:) method:

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

To manually handle push notifications, use userNotificationCenterHandler().

Returns:

A delegate that implements the YMPUserNotificationCenterDelegate protocol.

userNotificationCenterHandler()

class func userNotificationCenterHandler() -> YMPUserNotificationCenterHandling?

Returns a delegate YMPUserNotificationCenterHandling, which allows you to manually handle foreground push notifications on iOS 10 and higher.

Use this delegate if you implement the UNUserNotificationCenterDelegate protocol with custom logic. In this case, you should implement all methods of the UNUserNotificationCenterDelegate delegate and call the corresponding methods in YMPUserNotificationCenterHandling.

For simplified push notification handling, use userNotificationCenterDelegate()

Returns:

A delegate that implements the YMPUserNotificationCenterHandling protocol.