简体 EN 繁体

Getting Started For iOS

Index

1、Import TGSDK to the project

Using CocoaPods

If you use CocoaPods to manage the dependencies of your iOS project, please follow the steps below to import TGSDK:

First [go to download TSDDK's iOS SDK package] (https://support.yomob.com/docs/sdk/download/), download the zip file and unzip it, you will find it in the unzipped folder A Python script named generate_podspec.py, execute this script in this directory

` python ./generate_podspec.py `

After the script is successfully executed, the entire directory structure will become a local CocoaPods Repo.

Then import the private library just generated by the generate_podspec.py script as a dependency into your project

For example, the private library directory you just generated through the generate_podspec.py script is located at

/ Users / yomob / cocoapodsTGSDK

Then the method you introduced in your project Podfile file is

platform: ios, '8.0'
use_frameworks!

target 'MyApp' do
   pod 'TGSDK',: path => '/ Users / yomob / cocoapodsTGSDK'
end

Then use the command below to install TGSDK:

pod install

Cocos2d-x Project using CocoaPods requires additional work

If your project is based on cocos2d-x using CocoaPods to integrate TGSDK,please complete the below four additional steps and settings:

$(inherited)

As shown below:

cocoapods cocos2d-x Setting 1 cocoapods cocod2d-x Setting 2

We recommend to use CocoaPods to install TGSDK,it is easy and fast,if you use CocoaPods and finish the above four steps and settings,then jump to the second chapter on how to use TGSDK!

Copy TGSDK files to the project

First, download the latest TGSDK official version from yomob Official Website SDK download page. After decompression, you can view the directory structure shown in the following figure:

TGSDK File Structure

Then, copy the three file folders frameworksincluderesources and the static link lib file libTGSDK.x.x.x.a to your project.

Add dependency

Import the link libs of TGSDK dependency

libc++.tbd
libresolv.9.tdb
libsqlite3.tbd
libxml2.tbd
libz.tbd
Accelerate.framework
AdSupport.framework
AudioToolbox.framework
AVFoundation.framework
CFNetwork.framework
CoreFoundation.framework
CoreGraphics.framework
CoreLocation.framework
CoreTelephony.framework
CoreMedia.framework
CoreMotion.framework
CoreVideo.framework
EventKit.framework
Foundation.framework
GLKit.framework
iAd.framework
ImageIO.framework
MediaPlayer.framework
MessageUI.framework
MobileCoreServices.framework
QuartzCore.framework
SafariServices.framework
Security.framework
Social.framework
StoreKit.framework
SystemConfiguration.framework
VideoToolbox.framework
WatchConnectivity.framework
WebKit.framework
JavaScriptCore.framework
UIKit.framework

If you use cocos2d-x you also need to add additional dependencies GameController.framework

Note: WatchConnectivity.framework is relied on by advertiser AdColony, which may cause some older versions of Unity3D out of the package to be unapproved by Apple, either by updating the Unity3D version or by removing AdColony.framework and WatchConnectivity.framework To solve

Note: If you want to support iOS8.0 or earlier, you must set the libraries that can only be used by iOS9.0 or higher, such as CoreFoundation.framework and WatchConnectivity.framework, to Optional, and TGSDK will limit the startup of related SDKs.

Import the static link lib files libTGSDK.x.x.x.a under the directory of TGSDK and the lib files under the directory of frameworks to the project.

TGSDK iOS dependency import

Import all resource files under resources folder in TGSDK directory into your project.

Import TGSDK iOS resource file

Apply for certain permissions

Since AdColony is dependent on EventKit.framework, according to Apple Official Document, please apply for this permission after iOS 10.0. Or else it may cause your app to crash. Therefore, please add the below config into the Info.plist file.

<key>NSCalendarsUsageDescription</key>
<string>Some ad content may create a calendar event.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Some ad content may require access to the photo library.</string>
<key>NSCameraUsageDescription</key>
<string>Some ad content may access camera to take picture.</string>
<key>>NSMotionUsageDescription</key>
<string>Some ad content may require access to accelerometer for interactive ad experience.</string>

Attention! The above permissions are all required by the advertiser AdColony. If the product is sensitive to permissions or cannot be approved by Apple due to permission issues, it can be resolved by deleting the AdColony.framework ad plugin and removing the above permission request.

Important note about Google AdMob ad docking

According to the requirements of [Google AdMob latest docking document] (https://developers.google.com/admob/ios/quick-start#update_your_infoplist), the following configuration items must be added to the Info.plist file of your project

<key>GADApplicationIdentifier</key>
<string>ca-app-pub-8385434067230970~5771659843</string>

Otherwise, your project will crash during the use of Google AdMob ads.

But the ca-app-pub-8385434067230970~5771659843 filled in the above example is our test advertising account application ID registered with Google AdMob, which is only convenient for testing and cannot be used online Production Environment.

【Attention! ! ! 】 When your product is ready to be officially launched, please contact our operations staff to obtain the advertising account ID for your application,

After obtaining the advertising account ID from our operations staff, you are required to replace the corresponding value correctly to ensure that you can use the Google AdMob advertising service correctly.

Adjust compilation settings

Add -ObjC to Build Settings ----> Other Linker Flags configuration item.

Note: Cocos2d-x based iOS projects need attention,due to Cocos2d-x features,Project's Other Linker Flags has four settings, all these four settings require you to add the -ObjC option.

Cocos2d-x -ObjC Setting

Cocos2d-x Support

If you use Cocos2d-x to develop your app, we provide another convenient solution for integration with TGSDK. Cocos2d-x projects with support for JavaScript and Lua. Please refer to

iOS Project BitCode Support

Since version 1.6.1 of iOS(Including Unity) TGSDK supports iOS BitCode technology, you can enable BitCode support in your project.

Note: Support BitCode will increase the size of TGSDK as well as the build package,however the App download size from the Apple App Store will be less than the original size. Therefore, developers can safely enable BitCode support once needed

iOS 14

Since iOS14 will support AppTrackingTransparency (ATT) and SKAdNetwork. The developer's product is required to make the following special adaptations for iOS14.

AppTrackingTransparency

AppTrackingTransparency enables the developer's application to obtain the user's IDFA to require a pop-up window and the user's consent, which improves the transparency of user privacy. If you need to apply to the user to obtain the IDFA, you need to add the following permission to apply for configuration in the Info.plist file.

<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>

SKAdNetworks ID

SKAdNetwork is Apple's attribution solution for iOS 14, which can complete advertising attribution while protecting user privacy. After using SKAdNetwork, even if IDFA is not available, the attribution results of app installation can be correctly obtained. In order to support the use of Apple’s conversion tracking SKAdNetwork, the following advertiser’s attribution SKAdNetwork ID needs to be added to the Info.plist file

<key>SKAdNetworkItems</key>
<array>

    <!-- ironsource -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>su67r6k2v3.skadnetwork</string>
    </dict>


    <!-- chartboost -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>f38h382jlk.skadnetwork</string>
    </dict>


    <!-- guangdiantong -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>f7s53z58qe.skadnetwork</string>
    </dict>


    <!-- sigmob -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>58922nb4gd.skadnetwork</string>
    </dict>


    <!-- unityads -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>4dzt52r2t5.skadnetwork</string>
    </dict>


    <!-- mobvista -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>kbd757ywx3.skadnetwork</string>
    </dict>


    <!-- tapjoy -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>ecpz2srf59.skadnetwork</string>
    </dict>


    <!-- applovin -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>ludvb6z3bs.skadnetwork</string>
    </dict>


    <!-- vungle -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>gta9lk7p23.skadnetwork</string>
    </dict>


    <!-- admob -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>cstr6suwn9.skadnetwork</string>
    </dict>


    <!-- bytedance -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>238da6jt44.skadnetwork</string>
    </dict>

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>22mmun2rn5.skadnetwork</string>
    </dict>


    <!-- adcolony -->

    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>4pfyvq9l8r.skadnetwork</string>
    </dict>


</array>

2、Initialize TGSDK

After registering an account and creating your App on yomob Official Website you will acquire the corresponding product AppID from the website, and then use this parameter to initialize TGSDK

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [TGSDK initialize:@"Your application ID from yomob"
             callback:nil];
    [TGSDK preloadAd:nil];
    return YES;
}

3、Preload Ads Resources

To have enough time to load ads resources, it is recommended to call the preload API to load ads as early as possible. You can even call the preload API to load ads as soon as you initialize TGSDK.  

[TGSDK preloadAd:nil];

Note: The Bundle ID must match with the one you have registered under the App config in YoMob. Or else, you might not be able to load and play the ads

4、Play Ads

First, please create ad scenes for the registered App via yomob Official Website. After acquiring the corresponding ad scene ID, you can use it to verify whether the ads are ready. If the ads of the corresponding scene are ready, the video ads play API can be called to play the ads.

if ([TGSDK couldShowAd:@"Your scene id from Yomob") {
    [TGSDK showAd:@"Your scene id from Yomob"];
}

Note: If your application is a non-game application, or if there are multiple ViewControllers, you should use the show:WithViewController: interface to pass in the current ViewController, otherwise it will not play properly

5、Advanced Usage

Enable Debug mode

After enabling Debug mode, extra debug information is reported to the logs. This is convenient for locating problems.

Note: Do not use Debug mode under a production environment. In addition, if it is necessary to enable Debug mode, set Debug mode enabled before calling the initialization API.

[TGSDK setDebugModel:YES];

Set monitoring on ads preload event

You can monitor the ads loading process via a delegate.

@protocol TGPreloadADDelegate <NSObject>
@optional

// Ads preload calling succeeds
- (void) onPreloadSuccess:(NSString*)result;

// Ads preload calling fails
- (void) onPreloadFailed:(NSString*)result WithError:(NSError*) error;

// Award video ads are ready
- (void) onAwardVideoLoaded:(NSString*) result;

// Static interstitial video ads are ready
- (void) onInterstitialLoaded:(NSString*) result;

// Interstitial video ads are ready
- (void) onInterstitialVideoLoaded:(NSString*) result;

@end

Monitor preload process via delegate when calling preload API.

[TGSDK preloadAd:id<TGPreloadADDelegate> delegate];

Set monitoring on ads playing behavior event

Monitor events occurred during ads playing process via delegate.

@protocol TGADDelegate <NSObject>
@optional

// Ads is successfully played, and the sceneId and the corresponding advertiser result are the same.
- (void) onShow:(NSString* _Nonnull)scene Success:(NSString* _Nonnull)result;

// Ads fail to play
- (void) onShow:(NSString* _Nonnull)scene Failed:(NSString* _Nonnull)result Error:(NSError* _Nullable)error;

// After a user clicks ads, the ads playing page skips to other pages
- (void) onAD:(NSString* _Nonnull)scene Click:(NSString* _Nonnull)result;

// Ads is closed and the callback is called to indicate whether to give the reward
- (void) onAD:(NSString* _Nonnull)scene Close:(NSString* _Nonnull)result Award:(BOOL)award;

@end

Set below delegate to monitor ads behaviors via the following APIs.

[TGSDK setADDelegate:id<TGADDelegate> delegate];

[Note] If the Banner type ad callback onShow: Failed: Error: indicates that the ad failed to load and the ad does not display properly, you need to manually call [TGSDK closeBanner:scene] to close the currently displayed Banner, then you can try again. Call [TGSDK showAd:scene] to re-display the Banner ad.

Ads Test Tool

This functionality is only available in TGSDK with version 1.6.5 or above,we recommend you to upgrade your TGSDK for better a experience

Please do not use this function in a production environment . It is only for testing

During the testing phase, you can use APIs provided by Ads Test Tool instead of original ads API to better test your in App ads view logic.

Use Ads Test Tool API

[TGSDK showTestView:@"Your scene id from Yomob"];

Instead of using the original API

[TGSDK showAd:@"Your scene id from Yomob"];

The below UI will popup,you can test the Ads plugins included by test watching the available ads provided by these Ads networks included.

TGSDK_showTestView