# SKAdNetwork ID Auto Updater

The iOS SKAdNetwork ID Auto Updater is a build automation tool that keeps your `Info.plist` file synchronized with the latest SKAdNetwork IDs from your advertising partners during each build process. This ensures the list of supported ad network IDs remains current, even when partners update their IDs.

This article describes how to build, deploy, and integrate the tool into Xcode and Unity Editor.

## Installing the Auto Updater

Download the [DT SKAd\_updater](https://github.com/fyber-engineering/SKAd_updater) from GitHub. There are several methods to install the tool:

### Installing via Homebrew (Preferred)

1. Add the tap:

{% code title="Bash" %}

```bash
brew tap fyber-engineering/skad_updater
```

{% endcode %}

2. Install the application:

{% code title="Bash" %}

```bash
brew install skad_updater
```

{% endcode %}

### Downloading the Release Tar File

Download a specific release version from [SKAd\_updater](https://github.com/fyber-engineering/SKAd_updater/releases) on GitHub

1. Select the required release version.
2. Download the `.tar.gz` file and extract to your required folder

{% code title="Bash" %}

```bash
tar -xzf skad_updater-.tar.gz -C [folder-name]
```

{% endcode %}

3. Run the executable inside the inner `bin` folder.
4. (Optional) Add the executable to your `$PATH` to use `skad_updater` globally.

## Compiling the Source Code

Run all commands from the repository's root directory base folder.

### Prerequisites

Ensure the following dependencies are installed:

* macOS 10.15 or later
* curl
* OMake 3.18 or later
* Python 3.8 or later
* clang-format

### Automatic Build

Run this sequence to build the tool automatically:

{% code title="Bash" %}

```bash
./clean
./build
```

{% endcode %}

### Manual Build

Build the tool step by step:

{% code title="Bash" %}

```bash
./clean

cmake -S . -B build
cmake --build build --target format
cmake --build build --target fix-format
cmake --build build --target skad_updater
```

{% endcode %}

## Testing the Source Code

Verify the tool works correctly in your environment.

### Prerequisites

Ensure the following dependencies are installed:

* curl
* Python 3.8 or later
* Create a [virtual env](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/) under `tests/servermock` and install:

{% code title="Bash" %}

```bash
ip install -r requirements.txt
```

{% endcode %}

### Testing

Verify the tool works correctly in your environment.

{% code title="Bash" %}

```bash
cmake --build build --target tests_run
cd build/tests/
./tests_run
```

{% endcode %}

### Packaging

Generate a `.tar.gz` file in the build directory.

{% code title="Bash" %}

```bash
cmake --build build --target package
```

{% endcode %}

## Utilizing the Tool

### Synopsis

Run `skad_updater` from the terminal to update your `Info.plist` with the required SKAdNetwork IDs.

{% code title="Bash" %}

```bash
skad_updater ( (--help | -h) | (--show_networks) |
--plist_file_path [plist-file-path] (--network_list
[comma-separated-network-names] | --pod_file_path [pod-file-path])
[--dry_run] )
```

{% endcode %}

#### Network List Options

Define which networks to update:

* Explicit
  * Use `--show_networks` to show a list of supported ad networks.
  * Use `[--network_list <network-name-list>]` to show a parameter with a list of network names separated by a comma
* Automatic
  * Use `pod_file_path <pod-file-path>` to automatically derive networks from your Podfile, where `<pod-file-path>` is the path to the pod file.
* Combination
  * Use both `--network_list` and `pod_file_path` to combine explicit and automatic network lists.

### Parameters

The following table describes the network list parameters.

| **Parameter**     | **Value**                         | **Description**                                                                                                                                                                                                 |
| ----------------- | --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `plist_file_path` | `list-file-path`                  | Path to the target `Info.plist` file.                                                                                                                                                                           |
| `--network_list`  | `<comma-separated-network-names>` | Requests a specific list of networks to update. Provides a comma-separated list of network names as the argument, which you can combine with networks found in the Podfile.                                     |
| `pod_file_path`   | `<pod-file-path>`                 | <p>Update all the networks found in the Podfile.<br>Provide the Podfile path as the argument. Update additional networks not in the Podfile by including them in the <code>--network\_list</code> argument.</p> |

### Optional Parameters

| **Parameter**     | **Description**                                                              |
| ----------------- | ---------------------------------------------------------------------------- |
| `--dry_run`       | Performs a dry run and prints the updated plist file instead of overwriting. |
| `--show_networks` | Shows the list of supported networks.                                        |
| `--help, -h`      | Provides a help message and exit                                             |

### Examples

The following examples show how to use `skad_updater` with different parameters:

{% code title="Bash" %}

```bash
skad_updater --help
skad_updater --show_networks
skad_updater --plist_file_path <path-to-plist> --pod_file_path <path-to-podfile> --dry_run
skad_updater --plist_file_path <path-to-plist> --pod_file_path <path-to-podfile>
skad_updater --plist_file_path <path-to-plist> --network_list <csv-network-list> --dry_run
skad_updater --plist_file_path <path-to-plist> --network_list <csv-network-list>
skad_updater --plist_file_path <path-to-plist> --network_list <csv-network-list> --pod_file_path <path-to-podfile>
```

{% endcode %}

### Backups

The tool backs up the current `Info.plist` as `Info.plist.back.X` whenever it modifies the file. X increments with each backup.

### Reformatting the plist File

The Auto Updater formats the plist using standard XML indentation. Xcode may display slightly different formatting. To restore Xcode formatting:

{% code title="Bash" %}

```bash
plutil -convert xml1 [path_to_plist_file]
```

{% endcode %}

### Man Page

Use the manpage to read the usage instructions from the terminal:

{% code title="Bash" %}

```bash
$ man skad_updater
```

{% endcode %}

## Integrating into a Build Environment with Cocoapods

Use the `skad_updater` tool to automatically update your SKAdNetwork IDs during the build process.

### iOS

Manually add a Run Script Phase in Xcode to trigger the `skad_updater` tool.

![](https://content.gitbook.com/content/4IftQ9WUOy9feTA5sZeE/blobs/vcafcXUKwYf6nHCRJPSh/360012887658)

1. Open your Xcode project.
2. Select the project in the **Project Navigator**.
3. Select the **Build Phases** tab to enable the build phase menu items.
4. Click **Add** in the project editor to add build phases.
5. Select a **Run Script** phase and add the following shell script:

{% code title="Bash" overflow="wrap" %}

```bash
echo "$INFOPLIST_FILE" | sed 's/ /\\ /g' | (read SANITIZED_PATH; skad_updater --plist_file_path "$SANITIZED_PATH" --network_list=FairBidSDK --pod_file_path ./Podfile; plutil -convert xml1 "$SANITIZED_PATH")
```

{% endcode %}

6. Build your project.

The `skad_updater` tool automatically updates your `Info.plist` file.

### Unity

Use Unity's scripting APIs to automatically add a Build Phase that runs the `skad_updater` tool.

1. Export the Xcode project from Unity to add a Build Phase to Xcode, which will update the `Info.plist` file.
2. Add the Build Phase automatically and insert a run script using Unity's scripting APIs.\
   The script automatically inserts a Run Script Phase after the Xcode project is generated.
3. Add a new script file to the `Assets/Editor` folder in your Unity project, as in the following example.

{% code title="C#" %}

```csharp
using UnityEditor;
using UnityEditor.iOS.Xcode;
using UnityEditor.Callbacks;

public static class SKAdNetworkUpdater
{
    [PostProcessBuild(1)]
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        string projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject pbxProject = new PBXProject();
        pbxProject.ReadFromFile(projectPath);

#if UNITY_2019_3_OR_NEWER
        string targetGUID = pbxProject.GetUnityMainTargetGuid();
#else
        string targetGUID = pbxProject.TargetGuidByName("Unity-iPhone");
#endif

        string shellPath = "/bin/sh";
        int index = 0;
        string name = "Update SKAdNetwork ids";
        string shellScript = @"echo ""$INFOPLIST_FILE"" | sed 's/ /\\ /g' | (read SANITIZED_PATH; skad_updater --plist_file_path ""$SANITIZED_PATH"" --network_list=FairBidSDK --pod_file_path ./Podfile; plutil -convert xml1 ""$SANITIZED_PATH"")";
        pbxProject.InsertShellScriptBuildPhase(index, targetGUID, name, shellPath, shellScript);
        pbxProject.WriteToFile(projectPath);
    }
}
```

{% endcode %}

4. The `skad_updater` automatically updates your `Info.plist` file.

## Integrating into a Build Environment without Cocoapods

If you do not use CocoaPods, follow the same steps; however, instead of passing `<pod_file_path>`, use `--network_list` in the script to provide a comma-separated network list.
