Skip to content

Integrate SDK

Before you begin

The SDK initialization and delegate callbacks below apply to both AppDelegate and SceneDelegate lifecycles. Keep them in AppDelegate.

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

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

AppDelegate.m
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [SohaKit startWithDelegate:self
                    application:[UIApplication sharedApplication]
                    launchOptions:launchOptions
                    language:@"vi"];

    // vi : Vietnamese
    // en : English
    // zh : Chinese
    // id : Indonesian
    // th : Thai

    return YES;
}

@end

Danger

Call startWithDelegate exactly once from AppDelegate, including when using SceneDelegate. Do not initialize the SDK again when a scene connects.

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:(SohaUser *)user{
    // 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
}

Handle Application Events

Choose the case that matches your app's lifecycle. For the iOS SDK 27 scene requirement and submission deadline, see SceneDelegate.

Case 1: AppDelegate lifecycle

Keep the existing window setup in AppDelegate. Add the following to AppDelegate.m:

AppDelegate.m
- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    return [SohaKit application:app openURL:url options:options];
}

Case 2: SceneDelegate lifecycle

Keep SDK initialization and SohaDelegate callbacks in AppDelegate. SceneDelegate manages the window. Add the following to SceneDelegate.m:

SceneDelegate.m
#import <SohaSDK/SohaSDK.h>

- (void)scene:(UIScene *)scene
    openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
    [SohaKit openURLContexts:URLContexts];
}

If your app does not have a SceneDelegate yet, follow SceneDelegate to configure the scene and window.

Push Notifications

Make sure you enable Push Notifications in Signing & Capabilities.

Register for remote notifications

At startup or at the desired point in your application flow, call:

[SohaKit requestPushNotification];

This method registers for remote push notifications and handles the notification center's delegate internally.

Forward the APNs device token

Implement application:didRegisterForRemoteNotificationsWithDeviceToken: in AppDelegate.m and pass the APNs device token to the SDK. Keep this callback in AppDelegate even when using SceneDelegate.

AppDelegate.m
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [SohaKit registerDeviceToken:deviceToken];
}

Change SDK language

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

[SohaKit setLanguage:@"vi"];

    // vi : Vietnamese
    // en : English
    // zh : Chinese
    // id : Indonesian
    // th : Thai

Show in-app review - Rate App (Optional)

This feature is optional. Integrate it only if you want to show the review prompt, call the following method:

[SohaKit requestReview];