> For the complete documentation index, see [llms.txt](https://tyson.gitbook.io/vigamedoc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tyson.gitbook.io/vigamedoc/en/ke-hu-duan-jie-ru/ye-wu-jie-kou-1/2.-guang-gao-neng-li.md).

# 2.Advertising

## 2.1 Set AD result callback

### Android

```
ADNative.setAdResultCallback(AdParamCallback callback);
```

Example：

```
ADNative.setAdResultCallback(new ADManager.AdParamCallback() {

    @Override
    public void onStatusChanged(ADParam arg0, int status) {
        // TODO Auto-generated method stub
        Log.d(TAG,"onStatusChanged:"+status);
    }

    @Override
    public void onRequestAddGameCoin(ADParam arg0, int arg1, int arg2,
            String arg3) {
        // TODO Auto-generated method stub
        Log.d(TAG,"onRequestAddGameCoin");

    }

    @Override
    public void onOpenResult(ADParam adParam, int result) {
        // TODO Auto-generated method stub
        Log.d(TAG,"onOpenResult:"+result);
        //Determine if the ad type is a video
        if(adParam.getType().equals(ADDef.AD_TypeName_Video)){

        }

        if(result== ADParam.ADOpenResult_Success){//open success

        }
        else {//open fail

        }
    }
});
```

Callback Description：\
AdParamCallback .onOpenResult(onOpenResult(ADParam adParam , int result)) ：the result of openAd

* adParam: param of ad.
* result: 0-success 1-fail 2-cancel

AdParamCallback.onRequestAddGameCoin(ADParam adParam, int result, int num, String reason)：for integer wall(Depreciation)

* adParam: the param of ad &#x20;
* result：the result of openAd：0-success 1-fail 2-cancel &#x20;
* num：the num  of coin for rewards
* reason：reason for failure

## 2.2 Open AD

### 2.2.1 Open the general AD（interstitial/reward video/banner/splash）

### Android

```
ADNative.openAd(String adPositionName);
```

### iOS

```
[IOSLoader openAd:@"adPositioname"];
```

```
 [IOSLoader openAd:@"adPositioname" adCallback:^(BOOL flag, KTMADType type) {
        if (type == KTMADTypePlaque) {
            //qlaque
        }
        if (type == KTMADTypeVideo) {
            //Video
        }
    }];
```

Callback Description：

adCallback:^(BOOL flag, KTMADType type)：the callback of ad result。

* flag：true-open success false-open fail  (note:If the video play complete,flag will be true.)
* type ： KTMADTypePlaque（plaque），KTMADTypeVideo（video）

> Note: you shold close backgroud music when plaque or video open success.

Parameters：

* adPositionName： the name of position.

### Unity

```
Wb.ADManager.Instance.OpenAd(string adPositionName, Action<bool> callBackFun);
```

Example：

```
Wb.ADManager.Instance.OpenAd("home_mfzs", result =>
{
        if (result)
        {
            ShowToast("open success", false);
        }
        else
        {
            ShowToast("open fail", true);
        }
});
```

Parameters：

* adPositionName： the name of position
* callBackFun：the callback of openAd

#### Creator

```
Wb.Ad.openAd(adPositionName: string, callBackFun: Function);
```

Example：

```
Wb.Ad.openAd("home_mfzs", function (result: boolean) {
            if (result)
        {
            ShowToast("open success", false);
        }
        else
        {
            ShowToast("open fail", true);
        }
 });
```

* Parameters：
  * adPositionName： the name of position
  * callBackFun：the callback of openAd

### 2.2.2 Open the native AD（interstitial/reward video/banner/splash）

#### Android

```java
ADNative.openYsAd(String adPositionName,int width, int height, int x, int y,int limitSize);
```

params：

* adPositionName： the name of AD position
* width：width on the screen, in pixels&#x20;
* height：height on the screen, in pixels&#x20;
* x：X in the upper left corner，in pixels&#x20;
* y：Y in the upper left corner，in pixels&#x20;
* limitSize：We strongly recommend that you choose 1&#x20;

#### iOS

```objectivec
[IOSLoader openYsAd:string width:int height:int x:int y:int];
```

params：

* adPositionName： the name of AD position
* width：width on the screen, in pixels&#x20;
* height：height on the screen, in pixels&#x20;
* x：X in the upper left corner，in pixels&#x20;
* y：Y in the upper left corner，in pixels&#x20;

#### Unity

```
Wb.ADManager.Instance.OpenYsAd(String adPositionName,int width, int height, int x, int y,int limitSize);
```

params：

* adPositionName： the name of AD position
* width：width on the screen, in pixels&#x20;
* height：height on the screen, in pixels&#x20;
* x：X in the upper left corner，in pixels&#x20;
* y：Y in the upper left corner，in pixels&#x20;
* limitSize：We strongly recommend that you choose 1 &#x20;

```
Wb.ADManager.Instance.OpenYsAd(RectTransform rect, string adPositionName);
```

params：

* adPositionName：the name of AD position
* rect：Unity's coordinate region

```
Wb.ADManager.Instance.OpenYsAd(string adPositionName, float width, float height, float x, float y, float winSizeW, float winSizeH);
```

params：

* adPositionName： the name of AD position
* width：width on the screen, in pixels&#x20;
* height：height on the screen, in pixels&#x20;
* x：X in the upper left corner，in pixels&#x20;
* y：Y in the upper left corner，in pixels&#x20;
* winSizeW：Design resolution screen width
* winSizeH：Design resolution screen height

#### Creator

```
Wb.Ad.openYsAd(adPositionName: string, width: number, height: number, x: number, y: number, callback: Function);
```

params：

* adPositionName： the name of AD position
* width：width on the screen, in pixels&#x20;
* height：height on the screen, in pixels&#x20;
* x：X in the upper left corner，in pixels&#x20;
* y：Y in the upper left corner，in pixels&#x20;
* callBackFun：the callback of openAd

## 2.3 IS AD Ready

### Android

```
ADNative.isAdReady(String adPositionName);
```

```
ADNative.isAdReady2(String adPositionName, String type);
```

### iOS

```
[IOSLoader isAdReady:@"adPositioname"];
```

```
[IOSLoader isAdReady:@"adPositioname" type:@"type"];
```

### Unity

```
Wb.ADManager.Instance.IsAdReady(string adPositioname)
```

Parameters：

* adPositionName:the name of position
* type: Ad type (plaque, video, banner, wall, splash, msg)

### Creator

```
Wb.Ad.isAdReady(adPositionName: string);
```

Parameters：

* adPositionName:the name of position

## 2.4 Close AD

### Android

```
ADNative.closeAd(String adPositioname);
```

### iOS

```
[IOSLoader closeAd:@"adPositioname"];
```

### Unity

```
Wb.ADManager.Instance.CloseAd(string adPositioname);
```

Parameters：

* adPositionName： the name of position

### Creator

```
Wb.Ad.closeAd(adPositionName: string);
```

Parameters：

* adPositionName： the name of position

## 2.5 Get video limit open number

### Android

```
ADNative.getVideoLimitOpenNum();
```

### iOS

```
[IOSLoader getVideoLimitOpenNum];
```

### Unity

```
Wb.ADManager.Instance.GetVideoLimitOpenNum();
```

Return：

the num of limit open times，-1 is unlimited。

### Creator

```
Wb.Ad.getVideoLimitOpenNum();
```

Return：

the num of limit open times，-1 is unlimited。

## 2.6 is AD Opened（ **Deprecated** ）

### Android

```
ADNative.isAdOpen(String adPositionName);
```

### iOS

```
[IOSLoader isAdOpen:@"adPositionName"];
```

返回值：

* true-ad display on screen&#x20;
* false-ad is not display on screen

## 2.7 Is AD be opened in level

### Android

```
ADNative.isAdBeOpenInLevel(String adPositionname,int lv);
```

### iOS

```
[IOSLoader isAdBeOpenInLevel:@"adPositionName" level:lv];
```

### Unity

```
Wb.ADManager.Instance.IsAdBeOpenInLevel(string adPositionname,int lv);
```

Parameters：

* adPositionname：the name of position&#x20;
* lv：the number of level &#x20;

Return：

* true- support open&#x20;
* false-deny open

### Creator

```
Wb.Ad.isAdBeOpenInLevel(adPositionname: string, lv: number);
```

Parameters：

* adPositionname：the name of position&#x20;
* lv：the number of level &#x20;

Return：

* true- support open&#x20;
* false-deny open

## 2.8 Is AD type exist

### Android

```
ADNative.isAdTypeExist(String adType);
```

### iOS

```
[IOSLoader isAdTypeExist:@"adType"];
```

### Unity

```
Wb.ADManager.Instance.IsAdTypeExist(string adType)
```

Parameters：

* adType：（plaque, video, banner, wall, splash, msg） &#x20;

Return：

* true-exist&#x20;
* false-not exist

### Creator

```
Wb.Ad.isAdTypeExist(adType: string);
```

Parameters：

* adType：（plaque, video, banner, wall, splash, msg） &#x20;

Return：

* true-exist&#x20;
* false-not exist

## 2.9 Get AD position param

### Android

```
ADNative.getAdPositionParam(String positionName,String key);
```

### iOS

```
[IOSLoader getAdPositionParam:@"positionName" valueName:@"key"]
```

### Unity

```
Wb.ADManager.Instance.GetAdPositionParam(string positionName,string key);
```

Parameters：

* positionName-the name of position
* key-custom name

Return ：

the value of input key.

### Creator

```
Wb.Ad.getAdPositionParam(positionName: string, key: string);
```

Parameters：

* positionName-the name of position
* key-custom name

Return ：

the value of input key.
