# iOS

## CocoaPods

[CocoaPods](http://cocoapods.org/) is the easiest way to add devtodev into your iOS project.

1\. Firstly, install CocoaPods using:

```bash
sudo gem install cocoapods
```

2\. In the project directory execute the command:

```bash
pod init
```

3\. In the created Podfile add the dependency:

```bash
platform :ios, '9.0'

target 'TargetName' do
  use_frameworks!
  pod 'DTDAnalytics', '~> 2.0.0'
end
```

4\. Finally, run the command in your Xcode project directory:

```bash
pod install
```

CocoaPods should download and install the devtodev library, and create a new Xcode workspace. Open this workspace in Xcode.

## Swift Package Manager

In progress...

## Manual installation

1\. [Download the latest version of devtodev SDK from the repository  ](https://github.com/devtodev-analytics/ios-sdk-2.0)

2\. Add **`DTDAnalytics.xcframework`** to the project  (with ***Do Not Embed*** specified)![](blob:https://devtodev.atlassian.net/d3f72139-cd7c-442c-b432-817431ec55a2#media-blob-url=true\&id=922697d7-c4b5-4416-9bea-75ee0236eeb6\&collection=contentId-2520907789\&contextId=2520907789\&mimeType=image%2Fpng\&name=%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA%20%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0%202021-05-19%20%D0%B2%2017.39.13.png\&size=40783\&width=628\&height=168)

![](/files/-MgLxU1obl_4w8P4aKIH)

3\. Add frameworks:

* **`AppTrackingTransparency.framework`**
* **`AdSupport.framework`**

4\. Add initialization t&#x6F;**`didFinishLaunchingWithOptions`** method:

{% tabs %}
{% tab title="Swift" %}

```swift
let config = DTDAnalyticsConfiguration()
config.logLevel = .error
DTDAnalytics.initialize(applicationKey: "App ID", configuration: config)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
DTDAnalyticsConfiguration *config;
config.logLevel = DTDLogLevelError;
[DTDAnalytics applicationKey:@"App ID" configuration:config];
```

{% endtab %}
{% endtabs %}

* An **App ID** can be found in the settings of the respective app in devtodev (Settings → SDK → Integration → Credentials). &#x20;
* **`config`** - an object instance of **`DTDAnalyticsConfiguration`**, which is used for specifying additional properties during the initialization.

**`DTDAnalyticsConfiguration`**

| **Parameter**              | **Type**                 | **Description**                                                                                                                                                                                                                                                                                                                                  |
| -------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`currentLevel`**         | int                      | The player level at the moment of devtodev SDK initialization. It is recommended (but optional) to use to improve data precision.                                                                                                                                                                                                                |
| **`userId`**               | string                   | <p>A custom user identifier provided by the developer. If you utilize the default calculation by the device ID, this identifier can be used for finding a user in devtodev.</p><p>In case your project utilizes the calculation by the user identifier, you must set this parameter because it becomes the main user identifier in devtodev.</p> |
| **`trackingAvailability`** | DTDTrackingStatus (enum) | The property allows or disallows devtodev tracking of the user. By default, it is set to ***`DTDTrackingStatus.enable`***. SDK stores the previously assigned value. Pass ***`DTDTrackingStatus.disable`*** if the user opted out of tracking in line with GDPR.                                                                                 |
| **`logLevel`**             | DTDLogLevel (enum)       | The level of logging the SDK activity. The ***`DTDLogLevel.no`*** value is used by default. For troubleshooting during integration it is recommended to set it to ***`DTDLogLevel.debug`***, and either switch it off ***`DTDLogLevel.no`*** or use it only for error handling ***`DTDLogLevel.error`*** in the release version.                 |

Example:

{% tabs %}
{% tab title="Swift" %}

```swift
let config = DTDAnalyticsConfiguration()
config.currentLevel = 1
config.userId = "CustomUserID"
config.trackingAvailability = .enable
config.logLevel = .error
DTDAnalytics.initialize(applicationKey: "appKey", configuration: config)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
DTDAnalyticsConfiguration *config;
config.currentLevel = @1;
config.userId = @"CustomUserID";
config.trackingAvailability = DTDTrackingStatusEnable;
config.logLevel = DTDLogLevelError;
[DTDAnalytics applicationKey:@"App ID" configuration:config];
```

{% endtab %}
{% endtabs %}

### Integration features

#### **For Objective-C**

1. Create Bridging-Header. To do this, you need to add any swift file to the project (don’t delete it later) and choose ‘Create Bridging Header’ in the offered dialog box. &#x20;
2. Make sure that the ‘Build Settings’ for ‘Defines Module’ value evaluates to ‘YES’. &#x20;
3. While importing, use: **`#import <DTDAnalytics/DTDAnalytics-Swift.h>`**

#### **For SwiftUI**&#x20;

For SDK to function properly, it needs to be integrated at the earliest moment of the app launch. It is recommended that you use the following method of main entry point initialization:

```swift
@main
struct TestSwiftUIApp: App {
    init() {
        let config = DTDAnalyticsConfiguration()
        config.logLevel = .debug
        DTDAnalytics.initialize(applicationKey: "appKey", configuration: config)
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.devtodev.com/in-developing/integration-of-sdk/sdk-integration/ios.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
