Integrate SDK¶
Before you begin¶
- You must Install Soha SDK.
- You have downloaded and installed the
.p12
and.mobileprovision
files provided by SohaGame. - You must complete the Configure SDK Info
Initializing the iOS SDK¶
Import dependencies¶
Import SohaSDK
and set SohaDelegate to listen SDK events:
#import <SohaSDK/SohaSDK.h>
@interface AppDelegate: UIResponder<UIApplicationDelegate,SohaDelegate>
@end
Initialize the SDK¶
-
Setup main window for SDK in your app delegate's
If you use the Unity game engine, you can use the methodapplication(_:didFinishLaunchingWithOptions:)
method:UnityGetMainWindow()
to get the main window: -
Starting the SDK. In
didFinishLaunchingWithOptions
, callstartWithDelegate:application:launchOptions:loginManually:language:
:
Here's an example of Initialize the SDK
@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>Mã nhận dạng này sẽ được sử dụng để phân phối quảng cáo được cá nhân hóa cho bạn</string>
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: