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.
- 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.
To enable the library, add the following dependency to the Cartfile
and save the file:
github "yandexmobile/metrica-sdk-ios" ~> '3.5.0'
- Download the AppMetrica library.
- Add
YandexMobileMetrica.framework
to the project. - (Optional) To enable crash handling, add
YandexMobileMetricaCrashes.framework
. - Add the following dependencies: 'SystemConfiguration', 'UIKit', 'Foundation', 'CoreTelephony', 'CoreLocation', 'CoreGraphics', 'AdSupport', 'z', 'sqlite3', 'Security', 'c++', 'SafariServices' (with the Optional setting).
- Add
-ObjC
toOther Linker Flags
.
To enable the library, follow these steps:
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/Static-TV', '3.5.0'
-
Dynamic framework
pod 'YandexMobileMetrica/Dynamic-TV', '3.5.0'
To enable the library without crash handling, use the YandexMobileMetrica/Static-TV/Core
or YandexMobileMetrica/Dynamic-TV/Core
dependency.
- Download the AppMetrica library.
- Add
YandexMobileMetrica.framework
to the project from the tvos/static or tvos / dynamic directory. - (Optional) To enable crash handling, add
YandexMobileMetricaCrashes.framework
from the tvos/static or tvos/dynamic directory. - Add the following dependencies: 'SystemConfiguration', 'UIKit', 'Foundation', 'CoreTelephony', 'CoreLocation', 'CoreGraphics', 'AdSupport', 'z', 'sqlite3', 'Security', 'c++', 'SafariServices' (with the Optional setting).
- Add
-ObjC
toOther Linker Flags
.
To enable the library, follow these steps:
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
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Initializing the AppMetrica SDK.
YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:API_key];
[YMMYandexMetrica activateWithConfiguration:configuration];
}
Initialize the library in the initialize
method of the NSExtensionPrincipalClass
extension:
+ (void)initialize {
if ([self class] == [MMSTodayViewController class]) {
// Initializing the AppMetrica SDK.
YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:API_key];
[YMMYandexMetrica activateWithConfiguration:configuration];
}
}
Initialize the library in the initialize
method in Main Entry Point
of the extension (there may be multiple activation points):
+ (void)initialize {
if ([self class] == [MMSInterfaceController class]) {
// Initializing the AppMetrica SDK.
YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:API_key];
[YMMYandexMetrica activateWithConfiguration:configuration];
}
}
or
+ (void)initialize {
if ([self class] == [MMSNotificationController class]) {
// Initializing the AppMetrica SDK.
YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:API_key];
[YMMYandexMetrica activateWithConfiguration:configuration];
}
}

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