> For the complete documentation index, see [llms.txt](https://docs.funzy.vn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.funzy.vn/ios-fid-sdk/2.-sdk-integration.md).

# 2. SDK Integration

### 2.1 Initialization FID SDK

You can add initialization code in AppDelegate or anywhere you can control, notice some handler for KOLs configs

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

```objectivec
@import FTSDKCoreKit;
@import FTSDK;

// From v1.4.0, you need call @import AppsFlyerLib to config uninstall event
@import AppsFlyerLib;

// From v1.3.5, you need call [FIRApp configure] manually
@import FirebaseCore;

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    // Your code ...
    // From v1.3.5, you need call [FIRApp configure] manually
    [FIRApp configure];
    
    // Enable logging, disable when build Product
    [FTSDKConfig setDebug:YES];
    
    // Make sure choose environment match with license
    FTSDKConfig.env = 1; // 0: Product, 1: Development
    
    // You can turn on uninstall sanbox when in Development
    // [AppsFlyerLib shared].useUninstallSandbox = true;
    
    // Setting SDK language
    [[FTSDKAppDelegate instance] setLanguage: 1]; // 0: Vietnamese, 1: English
    
    
    // Turn off autologin if need (you need use FTSDK.requestAutoLogin function to check login manual)
    // FTSDKConfig.autoLogin = NO;

    // If you not using Info.plist key `FIDLicense`, then you can set FID license here
    // Make sure license match with `BundleId` and `env`
    [FTSDKConfig setSDKLicenseWithLicense:@"YOUR_SDK_LICENSE"];
    
    // Setting analytics configs
    [FTSDK didFinishLaunching:application with:launchOptions];
    
    // Your code ...
    
    // Setting notification
    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
    UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
    UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
    [[UNUserNotificationCenter currentNotificationCenter]
     requestAuthorizationWithOptions:authOptions
     completionHandler:^(BOOL granted, NSError * _Nullable error) {
        // Request ATT permission for tracking after request notification
        [[FTSDKTracking instance] requestTrackingAuthorization];
    }];
    
    // Request notification permission
    [application registerForRemoteNotifications];
    
    // FIRMessaging delegate, remember to implement UIApplicationDelegate, FIRMessagingDelegate
    [FIRMessaging messaging].delegate = self;
}

// Handle Universal Links for KOLs
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
    
    if ([FTSDK continue:userActivity restorationHandler:restorationHandler]) {
        return YES;
    }
    
    return NO;
}

// Handle callback when login with Facebook, Google,...
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    
    if ([FTSDK application:app open:url options:options]) {
        return YES;
    }
    return NO;
}

// Importance for notification and uninstall event
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [FIRMessaging messaging].APNSToken = deviceToken;
    
    [[FIRMessaging messaging] tokenWithCompletion:^(NSString *token, NSError *error) {
      if (error != nil) {
        NSLog(@"Error getting FCM registration token: %@", error);
      } else {
        NSLog(@"FCM registration token: %@", token);
      }
    }];
    
    // Add Appsflyer Uninstall measurement
    [[AppsFlyerLib shared] registerUninstall:deviceToken];
}


@end

```

{% endtab %}
{% endtabs %}

### 2.2 Handle FID SDK Ready

FID now is dynamic, all configs will fetch from server. Make sure FID is ready before use any FID's functions

Implement `FTSDKAuthDelegate` and use `onFTSDKIsReady` method:

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

```objectivec
- (void)onFTSDKIsReady {
    // Call when FID is ready, make sure you have wait before use any FID's functions
    
    // Example:
    // Verify Pending Transacions
    // Setup player info before make purchase
}
```

{% endtab %}
{% endtabs %}

View full `FTSDKAuthDelegate` in `3. FID Authentication`

### 2.3 Third Party Configs

FID iOS support login via Facebook, Google and Apple third party, but you need some config so it can work

#### 2.3.1 Google

Go to project target, at Info tab, add new URL Type with URL Schemes of Google (FTech will send with FID configs)

#### 2.3.2 Facebook

Go to project target, at Info tab, add new `URL Type` with `URL Schemes` of Facebook (FTech will send with FID configs)

Open your Info.plist file, add new key `FacebookClientToken` with Facebook Client Token (FTech will send with FID configs)
