Skip to content

Integrate SDK

Before you begin

Initializing the iOS SDK

Import dependencies

Import SohaSDK and set SohaDelegate to listen SDK events:

AppDelegate.h
#import <SohaSDK/SohaSDK.h>

@interface AppDelegate: UIResponder<UIApplicationDelegate,SohaDelegate>

@end

Initialize the SDK

  1. Setup main window for SDK in your app delegate's application(_:didFinishLaunchingWithOptions:) method:

    //Set SDK main window
    [SohaSetting settings].setWindow = self.window;
    
    If you use the Unity game engine, you can use the method UnityGetMainWindow() to get the main window:
    [SohaSetting settings].setWindow = UnityGetMainWindow();
    

  2. Starting the SDK. In didFinishLaunchingWithOptions, call startWithDelegate:application:launchOptions:loginManually:language::

    [SohaSetting setBaseURL:BaseURLProduct];
    
    [SohaSDK startWithDelegate:self
                   application:[UIApplication sharedApplication]
                 launchOptions:launchOptions
                 loginManually:YES
                      language:SohaSDKLanguageVietnam];
    

Here's an example of Initialize the SDK

AppDelegate.m
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //Set SDK main window.
    //If you use the Unity game engine, you can use the method UnityGetMainWindow() to get the main window
    [SohaSetting settings].setWindow = self.window;

    [SohaSetting setBaseURL:BaseURLProduct];

    [SohaSDK startWithDelegate:self
                    application:[UIApplication sharedApplication]
                    launchOptions:launchOptions
                    loginManually:YES
                    language:SohaSDKLanguageVietnamese];
}

@end

Danger

The startWithDelegate method should be called only one. Calling it multiple times may result in unpredictable errors.

Implementing SDK events

Through the use of SohaDelegate, you can listen for lifecycle events, such as when logged out or the status of the purchase.

-(void)sohaDidLogoutSuccess:(SohaUser *)user{
    // Called after logging out the current user
}

-(void)sohaDidDeleteAccountSuccess{
    // Called after successful user deletion
}

-(void)sohaDidPurchaseSuccess:(SohaTransaction *)transaction{
    // Called after successful completion of in-app purchase

}

-(void)sohaDidPurchaseFailed:(SohaTransaction *)transaction purchaseError:(NSString *)error{
    // Called after a failed in-app purchase
}

Listen App Delegate Events

Implement all the following methods of app delegate:

- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{

    return [SohaSDK application:app
                     openURL:url
                     options:options];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{
    return [SohaSDK application:application
        continueUserActivity:userActivity
          restorationHandler:restorationHandler];
}

Request App Tracking Transparency authorization

To display the App Tracking Transparency authorization request for accessing the IDFA, update your Info.plist to add the NSUserTrackingUsageDescription key with a custom message describing your usage. Here is an example description text:

<key>NSUserTrackingUsageDescription</key>
<string> nhận dạng này sẽ được sử dụng để phân phối quảng cáo được  nhân hóa cho bạn</string>
To present App Tracking Transparency authorization request, call requestTracking in applicationDidBecomeActive:
- (void)applicationDidBecomeActive:(UIApplication *)application{
    if (@available(iOS 14, *)){
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status){

        }];
    }
}

Change SDK language

When the application changes the language, update the SDK language with the following method:

[SohaSDK changeLanguage:SohaSDKLanguageEnglish];