# Import Triumph

## Import

{% tabs %}
{% tab title="Unity" %}
In your Unity project click on `Tools > TriumphSDK > Generate Unity Native Methods`

![](https://2867813904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1J5Yx5LRM1m9ejaniuNB%2Fuploads%2FLRN6v2Qu1YuyLgPL1UVM%2FScreenshot%202023-03-14%20at%2010.14.04%20AM.png?alt=media\&token=29afe3c0-ad66-4ede-9ae6-589ed2260fd9)

This will generate file `TriumphUnityNativeMethods`:&#x20;

```csharp
using UnityEngine;
using UnityEngine.SceneManagement;

namespace TriumphSDK
{
    public class TriumphUnityNativeMethods : MonoBehaviour, ITriumphUnityNativeMethods
    {
        // place your game ID here
        public static readonly string gameId = "";

        // place your merchant ID here
        public static readonly string merchantId = "";

        public void TriumphStartedGame()
        {
            /* TODO: implement method */
        }

        public void TriumphDidDismiss()
        {
            /* TODO: implement method */
        }

        public void TriumphDidPresent()
        {
            /* TODO: implement method */
        }

        public void TriumphWillDismiss()
        {
            /* TODO: implement method */
        }

        public void TriumphWillPresent()
        {
            /* TODO: implement method */
        }
    }
}
```

Then, you need to click `Tools > TriumphSDK > Generate API Prefab`

![](https://2867813904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1J5Yx5LRM1m9ejaniuNB%2Fuploads%2FgkQ1swIb7djmr1WHv7eL%2FScreenshot%202023-03-14%20at%2010.14.10%20AM.png?alt=media\&token=ce1584da-8e31-48cc-8f99-ed136f4ee67b)

Which will generate Prefab file called `TriumphAPI`. This prefab is an empty `GameObject` with two important `MonoBehaviour` components: `TriumphAPI` and `TriumphUnityNativeMethods`. Ensure that this prefab is in the first loaded scene of your game (i.e. the main menu).

<figure><img src="https://2867813904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1J5Yx5LRM1m9ejaniuNB%2Fuploads%2F1pEPeXBUA1knJYOqn47i%2FScreen%20Shot%202023-02-23%20at%203.10.30%20PM.png?alt=media&#x26;token=89779ba5-0e9f-4ccc-8186-de729f2c4ceb" alt=""><figcaption><p>Navigate to Assets -> Triumph -> Prefabs to find the TriumphAPI Prefab. Add it to the top level of your scene.</p></figcaption></figure>

Now, navigate to the `TriumphUnityNativeMethods` component of the `TriumphAPI` prefab. Grab the `gameId` for your game from the Triumph Dashboard (under your game's **go live** tab) and set it to the `gameId` variable in this file.&#x20;

```csharp
using UnityEngine;
using TriumphSDK;

public class TriumphUnityNativeMethods: MonoBehaviour, ITriumphUnityNativeMethods {
    
    // REQUIRED CONFIG IMPLEMENTATION 
    
    /*
     * Put your gameId here! Use gameId = "" if you want to test
     * out our Sandbox mode before creating a dev account
     */
    public static readonly string gameId = "YOUR_GAME_ID";
    
    /*
     * If you have playable or video tutorial within your game, 
     * please specify this by setting it to true
     */
    public static readonly bool hasTutorial = false;
}
```

{% endtab %}

{% tab title="Swift" %}
{% hint style="info" %}
Be sure to import TriumphSDK at the top level of any file that uses Triumph.
{% endhint %}

To configure Triumph Leaderboards, navigate to the `AppDelegate.swift willFinishLaunchingWithOptions` method, and add the configuration method `Triumph.configure`. Grab the `gameId` for your game from the Triumph Dashboard and pass it in as a parameter.

*Please note that it's required to configure Triumph in **willFinishLaunchingWithOptions***

```swift
import TriumphSDK

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        /*
        * @Params: 
        * gameId -- Your game ID
        */
        Triumph.configure(id: "YOUR_GAME_ID") 
        return true
} 
```

If you have playable or video tutorial within your game, please specify this setting within the configuration:

```swift
import TriumphSDK

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        /*
        * @Params: 
        * gameId -- Your game ID
        * options -- Configuration options
        */
        Triumph.configure(
                id: "YOUR_GAME_ID",
                options: .init(
                        hasTutorial: true // set to true if you have tutorial
                )
        ) 
        return true
} asd
```

Next, to receive push notifications you should pass the data in these `AppDelegate` methods:&#x20;

```swift
import TriumphSDK

func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
    Triumph.appLifecycle.didFinishLaunchingWithOptions(launchOptions)
    
    UNUserNotificationCenter.current().delegate = self
    // Instantiate your app
    
    return true
}
    
func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    didReceive response: UNNotificationResponse,
    withCompletionHandler completionHandler: @escaping () -> Void
) {
    Triumph.appLifecycle.userNotificationCenter(
        center, 
        didReceive: response, 
        withCompletionHandler: completionHandler
    )
}
    
func application(
    _ application: UIApplication, 
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
    Triumph.appLifecycle
        .didRegisterForRemoteNotificationsWithDeviceToken(deviceToken)
}
```

{% endtab %}
{% endtabs %}

You're now ready to integrate Triumph functionality into your game.
