Installation and initialization

The AppMetrica library consists of two frameworks: core and crash-handling. If you don't use AppMetrica crash handling, add only the core part of the library. This will reduce the size of the application.

The AppMetrica library supports the following platforms:
  • iOS
  • iOS Extension
  • iOS Watch version 1.x (beta)
  • tvOS

Step 1. Integrating the library

To connect the library, use the method for the appropriate platform:

The library can work with the following dependency managers:

The library supports static and dynamic frameworks for CocoaPods.

To connect the crash-handling framework, add the following dependency to your project's Podfile:

  • Static framework

    pod 'YandexMobileMetrica', '3.5.0'

    Example of enabling a static framework on GitHub.

  • Dynamic framework

    pod 'YandexMobileMetrica/Dynamic', '3.5.0'

To enable the library without crash handling, use the YandexMobileMetrica/Static/Core or YandexMobileMetrica/Dynamic/Core dependency.

Note. If the Podfile has the line use_frameworks!, we recommend using the dynamic framework.
If you don't use these dependency managers

To enable the library, follow these steps:

  1. Download the AppMetrica library.
  2. Add YandexMobileMetrica.framework to the project.
  3. (Optional) To enable crash handling, add YandexMobileMetricaCrashes.framework.
  4. Add the following dependencies: 'SystemConfiguration', 'UIKit', 'Foundation', 'CoreTelephony', 'CoreLocation', 'CoreGraphics', 'AdSupport', 'z', 'sqlite3', 'Security', 'c++', 'SafariServices' (with the Optional setting).
  5. Add -ObjC to Other Linker Flags.

Step 2. Initializing the library

To initialize the library, use the method for the appropriate platform:

Initialize the library in the application(_:didFinishLaunchingWithOptions:) method of your UIApplicationDelegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool
{
    // Initializing the AppMetrica SDK.
    let configuration = YMMYandexMetricaConfiguration.init(apiKey: "API_key")
    YMMYandexMetrica.activate(with: configuration!) 
}
What is the API key?
The API key is a unique application identifier that is issued in the AppMetrica web interface during app registration. Make sure you have entered it correctly.

AppMetrica allows tracking pre-installed apps. For more information, see Tracking pre-installed apps.

Note. Requirements: deployment target 8.0 and higher.