---
metadata:
  - name: generator
    content: Diplodoc Platform v5.70.2
alternate:
  - https://appmetrica.yandex.com.tr/docs/en/sdk/ios/analytics/objectivec/AMAAppMetricaConfiguration.md
  - https://appmetrica.yandex.com.tr/docs/ru/sdk/ios/analytics/objectivec/AMAAppMetricaConfiguration.md
  - https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/objectivec/AMAAppMetricaConfiguration.md
  - href: https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/objectivec/AMAAppMetricaConfiguration.md
    type: text/markdown
    title: Markdown version
  - href: https://appmetrica.yandex.com.tr/docs/zh/llms.txt?revision=r22165827
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://appmetrica.yandex.com.tr/docs/zh/llms.txt?revision=r22165827

# AMAAppMetricaConfiguration 类

此类包含库的扩展启动配置。

扩展配置的参数从库初始化时开始生效。

## Instance methods {#instance_summary}

#|
|| [-initWithAPIKey:](#method_initWithAPIKey) | 使用指定的 API 密钥初始化 `AMAAppMetricaConfiguration` 类的实例。 ||
|#

## Properties {#property_summary}

#|
|| [APIKey](#property_APIKey) | 应用的API密钥。 ||
|| [精确位置跟踪](#property_accurateLocationTracking) | 为内部位置管理器启用/禁用精确位置搜索。 ||
|| [advertisingIdentifierTrackingEnabled](#property_advertisingIdentifierTrackingEnabled) | 允许禁用发送IDFA，即使`AppMetricaAdSupport`模块已启用。 ||
|| [allowsBackgroundLocationUpdates](#property_allowsBackgroundLocationUpdates) | 启用/禁用后台跟踪位置更新。 ||
|| [appBuildNumber](#property_appBuildNumber) | 设置应用构建版本号用于AppMetrica报告。 ||
|| [appEnvironment](#property_appEnvironment) | 设置应用环境，从激活时刻起应用于所有事件。 ||
|| [appOpenTrackingEnabled](#property_appOpenTrackingEnabled) | 启用/禁用通过深链自动收集和发送关于应用启动的数据。 ||
|| [appVersion](#property_appVersion) | App版本。 ||
|| [customHosts](#property_customHosts) | 设置用于启动查询的代理 URL 地址AppMetrica。 ||
|| [自定义位置](#property_customLocation) | 设置设备的自定义位置。 ||
|| [dataSendingEnabled](#property_dataSendingEnabled) | 启用或禁用向 AppMetrica 服务器发送统计数据。 ||
|| [dispatchPeriod](#property_dispatchPeriod) | 设置自定义发送周期。 每次向服务器发送事件之间的间隔（秒）。 ||
|| [handleActivationAsSessionStart](#property_handleActivationAsSessionStart) | 定义 AppMetrica SDK 初始化为用户会话的开始。 此选项默认被禁用。 ||
|| [handleFirstActivationAsUpdate](#property_handleFirstActivationAsUpdate) | 将应用的首次启动定义为更新。 ||
|| [位置跟踪](#property_locationTracking) | 启用/禁用发送设备位置。 ||
|| [logsEnabled](#property_logsEnabled) | 启用/禁用记录库的活动。 ||
|| [maxReportsCount](#property_maxReportsCount) | 设置存储事件的最大数量。 ||
|| [maxReportsInDatabaseCount](#property_maxReportsInDatabaseCount) | 内部数据库中存储的错误报告最大数量。 ||
|| [preloadInfo](#property_preloadInfo) | 设置 [AMAAppMetricaPreloadInfo](https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/objectivec/AMAAppMetricaPreloadInfo.md) 类的实例，用于跟踪预安装的应用。 ||
|| [revenueAutoTrackingEnabled](#property_revenueAutoTrackingEnabled) | 启用/禁用自动收集应用内购买信息的功能。 ||
|| [sessionTimeout](#property_sessionTimeout) | 设置会话超时时间（秒）。 ||
|| [sessionsAutoTracking](#property_sessionsAutoTracking) | 启用/禁用自动跟踪应用生命周期。 ||
|| [userProfileID](#property_userProfileID) | 设置用户资料ID（`ProfileID`）在激活时。 ||
|#

## Method descriptions {#method_detail}

### -initWithAPIKey: {#method_initWithAPIKey}

```objectivec translate=no
- (instancetype)initWithAPIKey:(NSString *)APIKey
```

使用指定的 API 密钥初始化 `AMAAppMetricaConfiguration` 类的实例。

**参数：**

#|
|| `API密钥` | 应用的API密钥。 ||
|#

**返回：**

The `AMAAppMetricaConfiguration` 类实例。

## Property descriptions {#property_detail}

### APIKey {#property_APIKey}

```objectivec translate=no
@property (nonatomic, copy, readonly) NSString *APIKey;
```

应用程序的API密钥。

### accurateLocationTracking {#property_accurateLocationTracking}

```objectivec translate=no
@property (nonatomic, assign) BOOL accurateLocationTracking;
```

启用/禁用内部位置管理器的精确位置搜索。 默认禁用。

仅在位置跟踪设置为 `YES` 且位置未手动设置时才激活。

### advertisingIdentifierTrackingEnabled {#property_advertisingIdentifierTrackingEnabled}

```objectivec translate=no
@property (class, nonatomic, getter=isAdvertisingIdentifierTrackingEnabled) BOOL advertisingIdentifierTrackingEnabled;
```

允许禁用发送IDFA，即使`AppMetricaAdSupport`模块已启用。

### allowsBackgroundLocationUpdates {#property_allowsBackgroundLocationUpdates}

```objectivec translate=no
@property (nonatomic, assign) BOOL allowsBackgroundLocationUpdates;
```

启用/禁用后台跟踪位置更新。 默认禁用。

要启用后台位置更新跟踪，将属性设置为 `YES`.

### appBuildNumber {#property_appBuildNumber}

```objectivec translate=no
@property (nonatomic, copy, nullable) NSString *appBuildNumber;
```

设置应用构建号用于AppMetrica报告。

如果未设置，AppMetrica 将使用应用程序配置文件 `Info.plist` 中指定的应用构建号 (`CFBundleVersion`)。
应用构建号必须是一个数字字符串，可以转换为正整数。

### appEnvironment {#property_appEnvironment}

```objectivec translate=no
@property (nonatomic, copy, nullable) NSDictionary<NSString *, NSString *> *appEnvironment;
```

设置应用环境，从激活时刻起应用于所有事件。

### appOpenTrackingEnabled {#property_appOpenTrackingEnabled}

```objectivec translate=no
@property (nonatomic, assign) BOOL appOpenTrackingEnabled;
```

启用/禁用通过深链自动收集和发送应用启动数据的功能。

{% note alert %}

从 iOS AppMetrica SDK 4.0 版开始，应用通过 deeplinks 打开的事件会自动被跟踪。 对于其他版本，请手动设置跟踪：

- iOS AppMetrica SDK 版本低于 4.0。 [设置](https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/ios-operations.md#ui-app-delegate) UIApplicationDelegate 的深链追踪。
- [设置](https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/ios-operations.md#ui-scene-delegate) UISceneDelegate 的深链追踪（AppMetrica 不会自动追踪这种应用打开方式）。

自动跟踪仅记录导致应用启动的深链。 要跟踪运行中的应用中的深链，还需要设置[跟踪](https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/ios-operations.md)。

{% endnote %}

该选项默认已启用。

可能的值：

- `是`：已启用通过深链自动收集和发送关于应用启动的数据。
- `无`：通过深链自动收集并发送关于应用启动的数据已被禁用。

### appVersion {#property_appVersion}

```objectivec translate=no
@property (nonatomic, copy, nullable) NSString *appVersion;
```

App版本。

### customHosts {#property_customHosts}

```objectivec translate=no
@property (nonatomic, copy, nullable) NSArray *customHosts;
```

设置用于AppMetrica启动查询的代理URL。

### customLocation {#property_customLocation}

```objectivec translate=no
@property (nonatomic, strong, nullable) CLLocation *customLocation;
```

### dataSendingEnabled {#property_dataSendingEnabled}

```objectivec translate=no
@property (nonatomic, assign) BOOL dataSendingEnabled;
```

设置设备的自定义位置。

### dispatchPeriod {#property_dispatchPeriod}

```objectivec translate=no
@property (nonatomic, assign) NSUInteger dispatchPeriod;
```

设置自定义发送周期。 每次向服务器发送事件的间隔（秒）。

默认为90秒。 将值设置为 0 秒可防止库使用计时器自动发送事件。

### handleActivationAsSessionStart {#property_handleActivationAsSessionStart}

```objectivec translate=no
@property (nonatomic, assign) BOOL handleActivationAsSessionStart;
```

定义 AppMetrica SDK 初始化为用户会话的开始。

此选项默认被禁用。

可能的值：

- `是`：当库初始化时创建用户会话。
- `无`：在初始化库时会创建后台会话，在 [UIApplicationDidBecomeActiveNotification](https://developer.apple.com/documentation/uikit/uiapplicationdidbecomeactivenotification) 系统事件之后会创建用户会话。

### handleFirstActivationAsUpdate {#property_handleFirstActivationAsUpdate}

```objectivec translate=no
@property (nonatomic, assign) BOOL handleFirstActivationAsUpdate;
```

将应用的首次启动定义为更新。

{% note info %}

如果将应用的首次启动定义为更新，那么安装不会在报告中显示为新安装，也不会归属于伙伴。

{% endnote %}

可能的值：

- `是`：首次启动被定义为更新。
- `否`：首次启动被定义为新安装。

### locationTracking {#property_locationTracking}

```objectivec translate=no
@property (nonatomic, assign) BOOL locationTracking;
```

启用/禁用发送设备位置。

默认情况下，发送已启用。

### logsEnabled {#property_logsEnabled}

```objectivec translate=no
@property (nonatomic, assign, getter=areLogsEnabled) BOOL logsEnabled;
```

启用/禁用记录库的活动。

默认情况下，日志记录已禁用。

### maxReportsCount {#property_maxReportsCount}

```objectivec translate=no
@property (nonatomic, assign) NSUInteger maxReportsCount;
```

设置存储事件的最大数量。 自动发送报告的最小缓存事件数。

默认情况下，当存储中至少有7个项目时，事件会自动发送。

将值设置为 0 秒会阻止库在存储中达到设定事件数量时自动发送事件。

### maxReportsInDatabaseCount {#property_maxReportsInDatabaseCount}

```objectivec translate=no
@property (nonatomic, assign) NSUInteger maxReportsInDatabaseCount;
```

内部数据库中存储的错误报告最大数量。

允许的值范围是 [100; 10,000]。 超出此范围的值会自动替换为最接近范围边界的值。

默认值：1000。

{% note info %}

不同的数据库用于各个 `apiKeys`，并可以为它们设置独立的事件数量限制。 此参数仅影响对应的`apiKey`的限制。 要修改其他 `apiKeys` 的最大允许事件数，请使用 [AMAReporterConfiguration.maxReportsInDatabaseCount](https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/objectivec/AMAReporterConfiguration.md#property_maxReportsInDatabaseCount)。

{% endnote %}

### preloadInfo {#property_preloadInfo}

```objectivec translate=no
@property (nonatomic, copy, nullable) AMAAppMetricaPreloadInfo *preloadInfo;
```

设置 [AMAAppMetricaPreloadInfo](https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/objectivec/AMAAppMetricaPreloadInfo.md) 类的实例，用于跟踪预安装的应用。

要了解更多信息，请参见[跟踪预安装应用](https://appmetrica.yandex.com.tr/docs/zh/mobile-tracking/preinstalled-app-attr.md)。

### revenueAutoTrackingEnabled {#property_revenueAutoTrackingEnabled}

```objectivec translate=no
@property (nonatomic, assign) BOOL revenueAutoTrackingEnabled;
```

启用/禁用自动收集应用内购买信息的功能。

该选项默认已启用。

可能的值：

- `是`：已启用自动收集和发送应用内购买信息的功能。
- `无`：已禁用自动收集和发送应用内购买信息的功能。

### sessionTimeout {#property_sessionTimeout}

```objectivec translate=no
@property (nonatomic, assign) NSUInteger sessionTimeout;
```

设置会话超时时间（秒）。
默认值是`10`（最小允许值）。

要了解有关会话的更多信息，请参见[跟踪用户活动](https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/ios-listen.md)。

### sessionsAutoTracking {#property_sessionsAutoTracking}

```objectivec translate=no
@property (nonatomic, assign) BOOL sessionsAutoTracking;
```

启用/禁用自动跟踪应用程序生命周期。

该选项默认已启用。

如果该选项被禁用，您需要手动设置会话时长控制，使用 [+pauseSession:](https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/objectivec/AMAAppMetrica.md#method_pauseSession) 和 [+resumeSession:](https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/objectivec/AMAAppMetrica.md#method_resumeSession) 方法。 要了解更多信息，请参见[手动会话跟踪](https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/ios-listen.md)。

AppMetrica 使用 [UIApplicationDidBecomeActiveNotification](https://developer.apple.com/documentation/uikit/uiapplicationdidbecomeactivenotification) 和 [UIApplicationWillResignActiveNotification](https://developer.apple.com/documentation/uikit/uiapplicationwillresignactivenotification) 来跟踪会话。 最大会话时长为 24 小时。 要在24小时后延长会话，请手动调用[+resumeSession:](https://appmetrica.yandex.com.tr/docs/zh/sdk/ios/analytics/objectivec/AMAAppMetrica.md#method_resumeSession)方法。

### userProfileID {#property_userProfileID}

```objectivec translate=no
@property (nonatomic, copy, nullable) NSString *userProfileID;
```

设置用户资料ID（`ProfileID`）当激活时。

{% note alert %}

`ProfileID` 字符串的最大长度为 200 个字符。

{% endnote %}
