# Introduction

This guide is intended for developers who are integrating the AdView iOS SDK. After you have integrated the SDK, you must choose the relevant ad format and follow the steps for implementing that format.

# Prerequisites

- iOS 8.0+

## Step 1: Sign up and acquire app id

Before integration, you need to sign up on **AdView Mobile Marketplace** first and acquire a specific AdView App id **SDK-KEY** for each app you would like to integrate with AdView SDK. 

1. Sign up your publisher account at AdView Official Website:

<https://www.adview.com/web/overseas/register>

2. Sign in with your user name and password, AdView Publisher Dashboard opens
3. On the above menu bar, click **Apps**
4. On the left-up corner, click **+Add apps**

[![](https://gusaweb.adview.com/images/sdk/Sign-up-and-acquire-app-id-1.png)](https://gusaweb.adview.com/images/sdk/Sign-up-and-acquire-app-id-1.png "")

5. Fill in the app information step by step, please select the correct ad format, otherwise you might not get any ad fill. After filling all the necessary app information, please submit the app information for review. The review process generally takes one business day, please contact your account manager if any questions.

[![](https://gusaweb.adview.com/images/sdk/Sign-up-and-acquire-app-id-2.png)](https://gusaweb.adview.com/images/sdk/Sign-up-and-acquire-app-id-2.png "")

6. After the app has passed the review, the app **Status** will become **Passed** as below, please click **Configure** to config the ad network mediation configuration.

[![](https://gusaweb.adview.com/images/sdk/Sign-up-and-acquire-app-id-3.png)](https://gusaweb.adview.com/images/sdk/Sign-up-and-acquire-app-id-3.png "")

7. If you are using AdView’s ad network mediation feature, please click **Add ad platform** to add the ad networks you would like to support. If you are already using other ad mediation solutions, please simply turn the Advertising platform **AdViewBID** on and set the capacity to 100%. You can also find the specific AdView app id **SDK-KEY** here, which you will need for the SDK integration.

[![](https://gusaweb.adview.com/images/sdk/Sign-up-and-acquire-app-id-4.png)](https://gusaweb.adview.com/images/sdk/Sign-up-and-acquire-app-id-4.png "")

8. If your app’s ad format is Video or Native, you need to create **ad placement** for each ad place in your app. Please select **Ad Placement** on the above menu bar and click **+Ad Placement**, then add the necessary ad placement information accordingly.

[![](https://gusaweb.adview.com/images/sdk/Sign-up-and-acquire-app-id-5.png)](https://gusaweb.adview.com/images/sdk/Sign-up-and-acquire-app-id-5.png "")


## Step 2: Integration

### Manual SDK Download

1. Download the latest Version SDK here:

<https://www.adview.com/web/overseas/productAndTech/sdk>

2. Extract the zip file(Include: framework package, integration document, example)

### Import the framework into your project

- Put framework into your project, and add the dependency in YourProjectTarget's ```Build Phases``` - ```Link Binary With Libraries```.
- Add ```AdViewSDK.framework``` in ```Build Phases``` - ```Embed Frameworks```. 
- if you want to use omsdk feature, also ```OMSDK_AdView.framework``` will be imported.

```objc
dependencies:
    libc++.tbd
    libxml2.tbd
    AdSupport.framwork
    StoreKit.framewrok
    CoreTelephony.framework
```

### Update Your Project Settings

1. Declare the following permissions in your ```Info.plist```:

```objc
App Transport Security Settings - Allow Arbitrary Loads - YES
```

2. Declare the following Flags in your ```Build Settings```:

```objc
Build Settings - Other Linkr Flags - "-Objc"
```

## Step 3: Configure Ad Units in Your App

### Banner

Banner ads usually appear at the top or bottom of your app’s screen. Adding one to your app takes just a few lines of code.

Create an APP in the Publisher UI  for instructions. You will need that Ad Placement ID and SDK-KEY.

Usually when you add an app, you have the option of automatically ad banner or mrec  ad placement.

[![](https://gusaweb.adview.com/images/sdk/Configure-Ad-Units-in-Your-App-1.png)](https://gusaweb.adview.com/images/sdk/Configure-Ad-Units-in-Your-App-1.png "")

[![](https://gusaweb.adview.com/images/sdk/Configure-Ad-Units-in-Your-App-2.png)](https://gusaweb.adview.com/images/sdk/Configure-Ad-Units-in-Your-App-1.png "")

1. Init the Banner

The AdView SDK provides a UIView subclass ```AdViewView```, which handles requesting and loading ads. We provide the following methods for you to set up this subclass:
``` objc
+ (AdViewView *)requestBannerSize:(AdViewBannerSize)size
                       positionId:(NSString *)positionId
                         delegate:(id<AdViewViewDelegate>)delegate;
- (NSString *)appId;
```

```objc
    self.banner = [AdViewView requestBannerSize:AdViewBannerSize_320x50 positionId:nil delegate:self];
    [self.view addSubview:self.banner];
```

2. Init the MREC 

```objc
    self.MREC = [AdViewView requestBannerSize:AdViewBannerSize_300x250 positionId:nil delegate:self];
    [self.view addSubview:self.MREC];

- (NSString *)appId {
    return SDK-KEY;
}
```
return the ```SDK-KEY``` in protocol function ```- (NSString *)appId;```

Choose the ad size you need, we recommend 728x90 for tablet traffic and 320x50 for mobile traffic. The default size of MREC is 300x250, more define as following, all definitions are in ```AdViewDefinesPublic.h``` note the corresponding value. In addition, MREC currently supports the display of video advertisements, which will be described in detail below.

```objc
    typedef NS_ENUM(NSInteger, AdViewBannerSize) {
        AdViewBannerSize_320x50,
        AdViewBannerSize_480x44,
        AdViewBannerSize_300x250,   //MREC
        AdViewBannerSize_480x60,
        AdViewBannerSize_728x90,
    };
```

3. Should not change the Ad's bouns,because it may cause some error.But you can change the origin in the visible area.

4. Using the Delegate *AdViewViewDelegate.h*

which includes a variety of optional callbacks you can use to be notified of events.For example, when an ad has successfully loaded, or when the ad is about to present or dismiss a modal view. ```AdViewDelegate``` is a interface includes the following notifications:

```objc
@protocol AdViewViewDelegate <AdViewGDPRProcotol>
@required
- (NSString *)appId;
- (UIViewController *)viewControllerForShowModal;
@optional
- (void)didReceivedAd:(AdViewView *)adView;
- (void)didFailToReceiveAd:(AdViewView *)adView Error:(NSError*)error;
- (void)adViewWillPresentScreen:(AdViewView *)adView;
- (void)adViewDidDismissScreen:(AdViewView *)adView;
- (void)adViewDidFinishShow:(AdViewView *)adview;
- (int)autoRefreshInterval;
- (BOOL)logMode;
- (BOOL)testMode;
...
@end
```

### MREC Video

MREC supports the display of video advertisements, but for MREC video, you need to create a video ad placement:

[![](https://gusaweb.adview.com/images/sdk/MREC-Video-1.png)](https://gusaweb.adview.com/images/sdk/MREC-Video-1.png "")


And when you incoming the ad placement id ,fill the argument ***vPosID*** with *AdViewBannerManager*() construction, please use the video ad placement ID.

[![](https://gusaweb.adview.com/images/sdk/MREC-Video-2.png)](https://gusaweb.adview.com/images/sdk/MREC-Video-1.png "")

```objc
    self.MREC = [AdViewView requestBannerSize:AdViewBannerSize_300x250 positionId:ADVIEW_VIDEO_POSITION_ID delegate:self];
    [self.view addSubview:self.MREC];

- (NSString *)appId {
    return SDK-KEY;
}
```

### Interstitial

Interstitial ads provide full-screen experiences, commonly incorporating rich media to offer a higher level of interactivity compared to banner ads. Interstitials are typically shown during natural transitions in your app; for example, after completing a game level, or while waiting for a new view to load. 

Create an APP in the Publisher UI  for instructions. You will need that SDK-KEY.

Usually when you add an app, you have the option of automatically interstitial  ad placement.

[![](https://gusaweb.adview.com/images/sdk/Interstitial-1.png)](https://gusaweb.adview.com/images/sdk/Interstitial-1.png "")

1.    Create an Interstitial Ad

Income the ```delegate```、```SDK-KEY``` and ```viewControllerForShowModal``` complete interstitial initialization:

```objc
+ (AdViewView *)requestAdInterstitialWithDelegate:(id<AdViewViewDelegate>)delegate;
- (NSString *)appId;
```

```objc
    self.interstitial = [AdViewView requestAdInterstitialWithDelegate:self];
- (NSString *)appId {
    return SDK-KEY;
}

- (UIViewController *)viewControllerForShowModal {
    return ViewController;
}
```


2. Display an Interstitial Ad

When the advertisement is ready, you will receive the following callbacks:

```objc
- (void)didReceivedAd:(AdViewView *)adView
```

regularly , in *didReceivedAd:*, it means ad is ready and can be shown as you need, you can call the show method, then ad will pop up to screen:

```objc
- (void)didReceivedAd:(AdViewView *)adView {
    [adView showInterstitialWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
```

3. Using the Delegate

```AdViewViewDelegate.h``` provides a listener interface, which includes a variety of optional callbacks you can use to be notified of events; for example, when an ad has successfully loaded, or when the ad is about to present or dismiss a modal view. The same as Banner.


### Spread

Spread is usually an advertisement displayed at the start of app and usually has higher visibility than banner and insterstitial.

Create an APP in the Publisher UI  for instructions. You will need SDK-KEY.

[![](https://gusaweb.adview.com/images/sdk/Spread-1.png)](https://gusaweb.adview.com/images/sdk/Spread-1.png "")

1. Create an spread Ad

Income the following parameters and complete Spread initialization:

```objc
+ (AdViewView *)requestSpreadActivityWithDelegate:(id<AdViewViewDelegate>)delegate;
- (NSString *)appId;
- (UIViewController *)viewControllerForShowModal;
```

You should write these code in the ```AppDelegate.m```
``` objc
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    if (@available(iOS 13.0, *)) {

    } else {
        self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
        [self.window setBackgroundColor:[UIColor whiteColor]];
        
        ViewController * vc = [[ViewController alloc] init];
        UINavigationController * navc = [[UINavigationController alloc] initWithRootViewController:vc];
        [self.window setRootViewController:navc];
        [self.window makeKeyAndVisible];
    }
    [AdViewView requestSpreadActivityWithDelegate:self];
    return YES;
}
```

2. Display spread Ad

Usually spread will show automatically.

3. Using the Delegate

also, ```AdViewViewDelegate.h``` provides a listener interface, which includes a variety of optional callbacks you can use to be notified of events.

```objc
- (NSString *)appId;
- (UIViewController *)viewControllerForShowModal;
- (NSString *)logoImgName;
```

### Native

Native ads make it easy for you to monetize your app in a way that’s consistent with its existing design. The AdView SDK gives you access to an ad’s individual assets so you can design the ad layout to be consistent with the look and feel of your app.

Init the Native Ad You will need that Ad Position ID and SDK-KEY.

You need to choose the right creative and image size when creating native ad placement.

[![](https://gusaweb.adview.com/images/sdk/Native-1.png)](https://gusaweb.adview.com/images/sdk/Native-1.png "")

[![](https://gusaweb.adview.com/images/sdk/Native-2.png)](https://gusaweb.adview.com/images/sdk/Native-2.png "")

1. Create an AdView Native Ad:

```objc
- (instancetype)initWithAppKey:(NSString *)appkey positionID:(NSString *)positionID;
```

```objc
    self.native = [[AdViewNativeAd alloc] initWithAppKey:ADVIEW_APPID positionID:ADVIEW_NATIVE_POSITION_ID];
    self.native.delegate = self;
    self.native.controller = self;
```

2. Call ```-(void)loadNativeAdWithCount:``` to request an ad from the server and download associated images asynchronously.

```objc
    [self.native loadNativeAdWithCount:1];
```

3. Display native Ad, after ```- (void)adViewNativeAdSuccessToLoadAd:NativeData:``` callback is called when native ad is downloaded from server.
Upon failure ```- (void)adViewNativeAdFailToLoadAd:WithError:``` callback is called with a corresponding error code message.

```objc
- (void)adViewNativeAdSuccessToLoadAd:(AdViewNativeAd *)adViewNativeAd NativeData:(NSArray <AdViewNativeData *>*)nativeDataArray {
    //this is contentView, see demo
    self.nativeAdView = [[UIView alloc] init];

    //consuct the custom ad view

    //must use this function to send display
    [self.native showNativeAdWithData:nativeDataArray.firstObject
             friendlyObstructionArray:friendlyObstructionArray
                               onView:self.nativeAdView];
}


```

according to **AdViewNativeData.adProperties** is a list contains items as following:

**Normal native mode**:

Figure native4.1

| Name            | Value Type | Description                       |
| --------------- | ---------- | --------------------------------- |
| adIcon          | String     | icon url for adview icon          |
| adLogo          | String     | logo url for adview logo          |
| desc            | String     | description                       |
| title           | String     | ad title string                   |
| imageList       | Array      | large images for ad resource      |
| iconUrlString   | String     | icon for ad resource              |
| pimage          | String     | opt-out icon                      |
| pclick          | String     | opt-out click url                 |
| ompara、omurl、omvendor | String    | OMSDK                      |

5. Using the Delegate

```objc
@protocol AdViewNativeAdDelegate <AdViewGDPRProcotol>
- (void)adViewNativeAdSuccessToLoadAd:(AdViewNativeAd *)adViewNativeAd NativeData:(NSArray <AdViewNativeData *>*)nativeDataArray;
- (void)adViewNativeAdFailToLoadAd:(AdViewNativeAd *)adViewNativeAd WithError:(NSError *)error;
- (void)adViewNativeAdWillShowPresent;
- (void)adViewNativeAdClosed;
- (void)adViewNativeAdResignActive;
@end
```

#### Opt-out

In line with new industry self-regulatory guidance provided by the DAA, AdView now requires all native ads to display the privacy information icon and click region. The icon must be at least 20x20px and can be placed in any one of the four corners of the ad.
You can use your own icon and privacy information page, or use the corresponding icons and privacy information pages provided by AdView, You can get them with **pimage** and **pclick**, see Figure native4.1.

demo codes for got privacy image :

```objc
    NSString *optOutIconURL = data.adProperties[@"pimage"];
    UIImageView *optOutIcon = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:optOutIconURL]]]];
    optOutIcon.userInteractionEnabled = YES;
    UITapGestureRecognizer *optOutIconTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(optOutIconClick:)];
    [optOutIcon addGestureRecognizer:optOutIconTap];
```

demo codes for privacy click URL, you can got click url with ```NSString *optOutCilickURL = data.adProperties[@"pclick"];``` and show it by yourself.

```objc
//display privacy information
- (void)optOutIconClick:(id)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:optOutCilickURL]];
}
```

### Video

Video Ads are shown in fullscreen mode and can be placed before, in-between, or after the app content. 

#### Rewarded & Interstitial video 

Create an APP in the Publisher UI  for instructions. You will need that Ad Position ID and SDK-KEY.

[![](https://gusaweb.adview.com/images/sdk/Video-1.png)](https://gusaweb.adview.com/images/sdk/Video-1.png "")

[![](https://gusaweb.adview.com/images/sdk/Video-2.png)](hhttps://gusaweb.adview.com/images/sdk/Video-2.png "")


1. Create an Rewarded video Ad:

Income the following parameters and complete initialization:

```objc
    self.video = [AdViewVideo playVideoWithAppId:ADVIEW_APPID
                                      positionId:ADVIEW_VIDEO_POSITION_ID
                                       videoType:AdViewVideoTypeInstl
                                        delegate:self];
    [self.video setInterfaceOrientations:[UIApplication sharedApplication].statusBarOrientation];
    [self.video getVideoAD];
```

callback **AdViewVideoDelegate** is call capture events from video SDK process.

```objc
@protocol AdViewVideoDelegate <AdViewGDPRProcotol>
- (void)adViewVideoIsReadyToPlay:(AdViewVideo *)video;
- (void)adViewVideoPlayStarted;
- (void)adViewVideoPlayEnded;
- (void)adViewVideoClosed;
- (void)adViewVideoDidReceiveAd:(NSString *)vastString;
- (void)adViewVideoFailReceiveDataWithError:(NSError*)error;
```

AdView provides a response function ```- (void)adViewVideoDidReceiveAd:``` to let you know if the advertisement was successfully requested：

This function is called when the ad request is successful：

```objc
- (void)adViewVideoDidReceiveAd:(NSString *)vastString {
    NSLog(@"%@",vastString);
}
```

This function is called when an ad request fails：

```objc
- (void)adViewVideoFailReceiveDataWithError:(NSError *)error {
    NSLog(@"%@",error);
}
```

3. Called when the video ad is ready, after which video shows can be made：

```objc
- (void)adViewVideoIsReadyToPlay:(AdViewVideo *)video {
    [video showVideoWithController:self];
}
```

4. You can also monitor the following play status to determine rewards for users:

Called when video ads start playing

```objc
- (void)adViewVideoPlayStarted;
```


Called when video ads have ended

```objc
- (void)adViewVideoPlayEnded;
```

Called when the video ad is closed：

```objc
- (void)adViewVideoClosed;
```

Called when the video ad is playing incorrectly：

```objc
- (void)adViewVideoFailReceiveDataWithError:(NSError*)error;
```

#### PreMovie

PreMovie can provide  video source (means VAST xml content) to app , and SDK will not show  it . though app can parse vast itself and play it as it wish. 

Create an APP in the Publisher UI  for instructions. You will need that Ad Position ID and SDK-KEY.

[![](https://gusaweb.adview.com/images/sdk/Video-5.png)](https://gusaweb.adview.com/images/sdk/Video-5.png "")

[![](https://gusaweb.adview.com/images/sdk/Video-6.png)](https://gusaweb.adview.com/images/sdk/Video-6.png "")

1. Create an paste video ad:

```objc
    self.video = [AdViewVideo playVideoWithAppId:ADVIEW_APPID
                                      positionId:ADVIEW_VIDEO_POSITION_ID
                                       videoType:AdViewVideoTypePreMovie
                                        delegate:self];
```

2. Response for video ad received:
   with paste video mode, after ad video is received, the video contents will be pass through to app with callback *onReceivedVideo()*, in parameter string:

```objc
- (void)adViewVideoDidReceiveAd:(NSString *)vastString {
    NSLog(@"%@",vastString);
}  
```

3. Play & other process:

   same as rewarded video.


# GDPR

As a publisher, you should integrate a Consent Management Platform (CMP) and request for vendor and purpose consents as outlined in IAB Europe’s Mobile In-App CMP API v1.0: Transparency & Consent Framework. You can find a reference implementation of a web-based CMP and the corresponding native wrappers here in the IAB’s GDPR Transparency and Consent Framework. 

if you already got IABConsent_ConsentString, you just need pass through to SDK construction method as the last parameter.See ```AdViewViewDelegate.h``` - ```AdViewGDPRProcotol``` :


```objc
@protocol AdViewGDPRProcotol <NSObject>
- (BOOL)CMPPresent;
- (BOOL)subjectToGDPR;
- (NSString *)userConsentString;
- (NSString *)parsedPurposeConsents;
- (NSString *)parsedVendorConsents;
@end
```

if **String gdpr** is empty, it means not support GDPR.

#### CCPA
We support CCPA,you should use the NSUserDefaults to save the ```CCPA``` string for key ```"us_privacy"```
