AppMetrica Push SDK allows you to send targeted push notifications to app users. These notifications are called push campaigns. You can use push campaigns to engage your audience and help reduce churn.
- Go to File > Add Package Dependency.
- Put the GitHub link of the AppMetrica Push SDK: https://github.com/appmetrica/push-sdk-ios.
- In Add to Target, select None for modules you don't want.
- Add the SDK to your project's dependencies:
dependencies: [
.package(url: "https://github.com/appmetrica/push-sdk-ios", from: "2.0.0")
],
- List the modules in your target's dependencies:
.target(
name: "YourTargetName",
dependencies: [
.product(name: "AppMetricaPush", package: "push-sdk-ios"),
// Optionally include 'AppMetricaPushLazy' for lazy push feature
]
)
- If you haven't set up CocoaPods, run
pod init
in your project directory. - In your Podfile, add AppMetrica Push dependencies:
target 'YourAppName' do
# For all analytics features, add this umbrella module:
pod 'AppMetricaPush', '~> 2.0.0'
# Optionally add Lazy Push pod
pod 'AppMetricaPushLazy', '~> 2.0.0'
end
- Install the dependencies using
pod install
. - Open your project in Xcode with the
.xcworkspace
file.
AppMetricaPush
: Required for basic SDK use.AppMetricaPushLazy
: Enables lazy push support
Here's how to add AppMetrica Push SDK to your project (works for both SwiftUI and UIKit):
-
Add AppMetrica into project
-
import AppMetricaPush
. -
Configure AppMetricaPush by setting
UNUserNotificationCenter.current().delegate = AppMetricaPush.userNotificationCenterDelegate
inapplication(_:didFinishLaunchingWithOptions:)
. -
Register device token in
application(_:didRegisterForRemoteNotificationsWithDeviceToken:)
-
Call
UIApplication.registerForRemoteNotifications()
. See documentation to enable visible notifications. -
(Optional) If you also use
UISceneDelegate
addAppMetricaPush.handleSceneWillConnectToSession(with:)
inscene(_:willConnectTo:options:)
Put this in your AppDelegate.swift
:
import UIKit
import UserNotifications
import AppMetrica
import AppMetricaPush
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
if let configuration = AppMetricaConfiguration(apiKey: "Your_API_Key") {
AppMetrica.activate(with: configuration)
}
UNUserNotificationCenter.current().delegate = AppMetricaPush.userNotificationCenterDelegate
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
AppMetricaPush.setDeviceToken(deviceToken)
}
}
If you are using scenes, put this in your SceneDelegate.swift
import UIKit
import AppMetricaPush
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(_ scene: UIScene, willConnectTo
session: UISceneSession, options
connectionOptions: UIScene.ConnectionOptions) {
AppMetricaPush.handleSceneWillConnectToSession(with: connectionOptions)
}
}
For integrating AppMetrica Push SDK into a SwiftUI application, you can use an AppDelegate adapter to handle lifecycle events related to push notifications. Create a new AppDelegate.swift and set it up similarly to the UIKit approach:
Then in your App
struct:
@main
struct YourAppNameApp: App {
// Use the `@UIApplicationDelegateAdaptor` property wrapper to work with AppDelegate and set up AppMetrica Push SDK
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
You can find comprehensive integration details and instructions for installation, configuration, testing, and more in our full documentation.
AppMetrica Push SDK is released under the MIT License. License agreement is available at LICENSE.