Fascodes Ads Documents

vuePress-theme-reco Liang Hu    2020
Fascodes Ads Documents Fascodes Ads Documents

Choose mode

  • dark
  • auto
  • light
Home
広告SDK
  • Android
  • iOS
  • Web
広告配信
効果測定
管理画面へ (opens new window)
言語選択
  • English
  • 简体中文
  • 日本語

Liang Hu

0

文章

0

ラベル

Home
広告SDK
  • Android
  • iOS
  • Web
広告配信
効果測定
管理画面へ (opens new window)
言語選択
  • English
  • 简体中文
  • 日本語
  • 広告SDK

    • Android
    • iOS
    • Web
  • 広告配信

  • 効果測定

広告SDK(iOS)

vuePress-theme-reco Liang Hu    2020

広告SDK(iOS)

Liang Hu

# 1. 事前準備

  • Create a Fascode Ads account (If not, Create an account(opens new window) )
  • Register an app(Not yet? Go to Register an app(opens new window) )
  • Use Xcode 11 or higher
  • Target iOS 9.0 or higher

# 2. SDKをインポートする

# CocoaPods (推奨)

The simplest way to import the SDK into an iOS project is to use CocoaPods. Open your project's Podfile and add this line to your app's target:

pod 'Fascode-Ads-SDK'

Then from the command line run:

pod install --repo-update

If you're new to CocoaPods, see their official documentation(opens new window) for info on how to create and use Podfiles.

# 3. SDKの利用

# 3.1 Publisher ID取得

Go to Account(opens new window) to get the Publisher Id

# 3.2 Info.plist を更新する

Update your app's Info.plist file to add two keys:

A FascodeAdsPublisherId key with a string value of your Fascode Publisher ID (see 3.1 Retrieve the Publisher Id). A SKAdNetworkItems key with Fascode's SKAdNetworkIdentifier value of < To Be Defined >.

<key>FascodeADApplicationIdentifier</key>
<string><!-- Fascode Publisher ID --></string>
<key>SKAdNetworkItems</key>
  <array>
    <dict>
      <key>SKAdNetworkIdentifier</key>
      <string><!-- SKAdNetworkIdForFascode --></string>
    </dict>
  </array>

Or, edit it in the property list editor:

# 3.3 SDKを初期化する

Before loading ads, call the startWithCompletionHandler: method on the FascodeAds.shared, which initializes the SDK and calls back a completion handler once initialization is complete (or after a 30-second timeout). This only needs to be done once, ideally at app launch. You should call startWithCompletionHandler: as early as possible.

Here's an example of how to call the startWithCompletionHandler: method in your AppDelegate:

  • Swift








 






import FascodeAds

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  func application(_ application: UIApplication,
      didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    FascodeAds.shared().start(completionHandler: nil)

    return true
  }

}







 





@import FascodeAds;

@implementation AppDelegate

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

  [[FascodeAds shared] startWithCompletionHandler:nil];
  return YES;
}

@end

# 4. 広告ユニットを作成する

You need to create one or more Ad Units in the Fascode Ads console in advance, the created Ad Units represents what will be displayed and how.

# 4.1 広告フォーマットを選択する

For Android App, you can choose to show the following types of ads.

  • Banner Ad
  • Interstitial Ad
  • Video Ad
  • Custom Ad
  • Reward Ad

Tips

  • Reward Ad is actually using other types but supposed to be interact with your app, such as reward users for watching over an video ad.

# 4.2 広告ターゲッティングを選択する

By default all kinds of targetings are picked for your Ad Unit, but of course you can manually pick up the best ones to optimize your advertising.

# 4.3 Set the refresh interval(Banner Ad only)

For Banner Ad, you can change the refresh interval to decide how many seconds to refresh the ads.

# 4.4 Save Ad Unit

Click Save, an Ad Unit ID will be generated to be used by SDK in your app.

# 5. Show Ad

# 5.1 Banner Ad

# Add BannerAd to layout

Banner Ads are displayed in FADBannerView objects, so the first step toward integrating banner ads is to include a FADBannerView in your view hierarchy. This is typically done either with the Interface Builder or programmatically.

  • Interface Builder A FADBannerView can be added to a storyboard or xib file like any typical view. When using this method, be sure to add width and height constraints to match the ad size you'd like to display. For example, when displaying a banner (320x50), use a width constraint of 320 points, and a height constraint of 50 points.

  • Programmatically A FADBannerView can also be instantiated directly. Here's an example of how to create a FADBannerView, aligned to the bottom center of the safe area of the screen, with a banner size of 320x50:









 
 


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


import FascodeAds
import UIKit

class ViewController: UIViewController {
  var bannerView: FADBannerView!

  override func viewDidLoad() {
    super.viewDidLoad()
    bannerView = FADBannerView(adSize: kFADAdSizeBanner)
    addBannerViewToView(bannerView)
  }

  func addBannerViewToView(_ bannerView: FADBannerView) {
    view.addSubview(bannerView)
    view.addConstraints(
      [NSLayoutConstraint(item: bannerView,
                          attribute: .bottom,
                          relatedBy: .equal,
                          toItem: bottomLayoutGuide,
                          attribute: .top,
                          multiplier: 1,
                          constant: 0),
       NSLayoutConstraint(item: bannerView,
                          attribute: .centerX,
                          relatedBy: .equal,
                          toItem: view,
                          attribute: .centerX,
                          multiplier: 1,
                          constant: 0)
      ])
   }
}













 
 
 


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 





@import FascodeAds;

@interface ViewController ()

@property(nonatomic, strong) FADBannerView *bannerView;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  
  self.bannerView = [[FADBannerView alloc]
      initWithAdSize:kFADAdSizeBanner];
  [self addBannerViewToView:self.bannerView];
}

- (void)addBannerViewToView:(UIView *)bannerView {
  [self.view addSubview:bannerView];
  [self.view addConstraints:@[
    [NSLayoutConstraint constraintWithItem:bannerView
                               attribute:NSLayoutAttributeBottom
                               relatedBy:NSLayoutRelationEqual
                                  toItem:self.bottomLayoutGuide
                               attribute:NSLayoutAttributeTop
                              multiplier:1
                                constant:0],
    [NSLayoutConstraint constraintWithItem:bannerView
                               attribute:NSLayoutAttributeCenterX
                               relatedBy:NSLayoutRelationEqual
                                  toItem:self.view
                               attribute:NSLayoutAttributeCenterX
                              multiplier:1
                                constant:0]
                                ]];
}
  


@end

# Configure Banner's properties

In order to load and display ads, FADBannerView requires a few properties be set.

  • rootViewController - This view controller is used to present an overlay when the ad is clicked. It should normally be set to the view controller that contains the FADBannerView.
  • adUnitID - This is the ad unit ID from which the FADBannerView should load ads.

Here's a code example showing how to set the two required properties in the viewDidLoad method of a UIViewController:





 
 


override func viewDidLoad() {
  super.viewDidLoad()
  ...

  bannerView.adUnitID = "<Ad Unit ID>"
  bannerView.rootViewController = self
}




 
 



- (void)viewDidLoad {
  [super viewDidLoad];
  ...

  self.bannerView.adUnitID = @"<Ad Unit ID>";
  self.bannerView.rootViewController = self;
}

# Load an ad to Banner

Once the FADBannerView is in place and its properties configured, it's time to load an ad. This is done by calling loadRequest: on a FADRequest object:







 



override func viewDidLoad() {
  super.viewDidLoad()
  ...

  bannerView.adUnitID = "<Ad Unit ID>"
  bannerView.rootViewController = self
  bannerView.load(FADRequest())

}






 



- (void)viewDidLoad {
  [super viewDidLoad];
  ...

  self.bannerView.adUnitID = @"<Ad Unit ID>";
  self.bannerView.rootViewController = self;
  [self.bannerView loadRequest:[FADRequest request]];
}

Tips

Banner Ad is usually displayed at the bottom or top of the screen. Please ensure that the advertisement can be displayed normally and does not interfere with other views in the layout.

# 5.2 Interstitial Ad

# Create an interstitial ad object

Interstitial ads are requested and shown by FADInterstitial objects. The first step in using one is to instantiate it and set its ad unit ID. For example, here's how to create a FADInterstitial in the viewDidLoad method of a UIViewController:










 




import FascodeAds
import UIKit

class ViewController: UIViewController {

  var interstitial: FADInterstitial!

  override func viewDidLoad() {
    super.viewDidLoad()
    interstitial = FADInterstitial(adUnitID: "<Ad Unit ID>")
  }
}















 



@import FascodeAds;
@import UIKit;

@interface ViewController ()

@property(nonatomic, strong) FADInterstitial *interstitial;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  self.interstitial = [[FADInterstitial alloc] initWithAdUnitID:@"<Ad Unit ID>"];
}

FADInterstitial is a single-use object that will load and display one interstitial ad. To display multiple interstitial ads, an app needs to create a FADInterstitial for each one.

# Load an ad to interstitial

To load an interstitial ad, call loadRequest: on a FADRequest object:




 
 


override func viewDidLoad() {
  super.viewDidLoad()
  interstitial = FADInterstitial(adUnitID: "<Ad Unit ID>")
  let request = FADRequest()
  interstitial.load(request)
}





 
 


- (void)viewDidLoad {
  [super viewDidLoad];

  self.interstitial = [[FADInterstitial alloc]
      initWithAdUnitID:@"<Ad Unit ID>"];
  FADRequest *request = [FADRequest request];
  [self.interstitial loadRequest:request];
}

# 5.3 Video Ad

# Create an video ad object

Interstitial ads are requested and shown by FADInterstitial objects. The first step in using one is to instantiate it and set its ad unit ID. For example, here's how to create a FADInterstitial in the viewDidLoad method of a UIViewController:









 




import FascodeAds
import UIKit

class ViewController: UIViewController {
  var videoAd: FADVideo!

  override func viewDidLoad() {
    super.viewDidLoad()
    videoAd = FADVideo(adUnitID: "<Ad Unit ID>")
  }
}















 



@import FascodeAds;
@import UIKit;

@interface ViewController ()

@property(nonatomic, strong) FAdVideo *videoAd;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  self.interstitial = [[FAdVideo alloc] initWithAdUnitID:@"<Ad Unit ID>"];
}

FAdVideo is a single-use object that will load and play one video ad.

# Load an ad to video ad

To load an video ad, call loadRequest: on a FADRequest object:




 
 


override func viewDidLoad() {
  super.viewDidLoad()
  videoAd = FADVideo(adUnitID: "<Ad Unit ID>")
  let request = FADRequest()
  videoAd.load(request)
}



 
 


- (void)viewDidLoad {
  [super viewDidLoad];
  self.videoAd = [[FADVideo alloc] initWithAdUnitID:@"<Ad Unit ID>"];
  FADRequest *request = [FADRequest request];
  [self.videoAd loadRequest:request];
}

# 5.4 Custom Ad

If you choose Custom Ad type for your Ad Unit, you will have a fixed and completely owned ad displayed. To implement it in your app, use the same ways for 5.1 Banner Ad,5.2 Interstitial Ad ,5.3 Video Ad.

# 5.5 Reward Ad

To encourage users to watch over an Ad, you can reward them with some in-app goods or coins, with listening the 6. Ad Events, you can easily implement it.

# 6. Ad Event

# 6.1 Registering for banner events

To register for banner ad events, set the delegate property on FADBannerView to an object that implements the FADBannerViewDelegate protocol. Generally, the class that implements banner ads also acts as the delegate class, in which case, the delegate property can be set to self.

Tips

For FADInterstitial use FADInterstitialDelegate For FADVideo, use FADVideoDelegate




 





 




import FascodeAds
import UIKit

class ViewController: UIViewController, FADBannerViewDelegate {
  var bannerView: FADBannerView!

  override func viewDidLoad() {
    super.viewDidLoad()
    ...
    bannerView.delegate = self
  }
}



 










 



@import FascodeAds;

@interface ViewController () <FADBannerViewDelegate>

@property(nonatomic, strong) FADBannerView *bannerView;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  ...
  self.bannerView.delegate = self;
}

# 6.2 Implementing banner events

Each of the methods in FADBannerViewDelegate is marked as optional, so you only need to implement the methods you want. This example implements each method and logs a message to the console:

/// Tells the delegate an ad request loaded an ad.
func adViewDidReceiveAd(_ bannerView: FADBannerView) {
  print("adViewDidReceiveAd")
}

/// Tells the delegate an ad request failed.
func adView(_ bannerView: FADBannerView,
    didFailToReceiveAdWithError error: FADRequestError) {
  print("adView:didFailToReceiveAdWithError: \(error.localizedDescription)")
}

/// Tells the delegate that a full-screen view will be presented in response
/// to the user clicking on an ad.
func adViewWillPresentScreen(_ bannerView: FADBannerView) {
  print("adViewWillPresentScreen")
}

/// Tells the delegate that the full-screen view will be dismissed.
func adViewWillDismissScreen(_ bannerView: FADBannerView) {
  print("adViewWillDismissScreen")
}

/// Tells the delegate that the full-screen view has been dismissed.
func adViewDidDismissScreen(_ bannerView: FADBannerView) {
  print("adViewDidDismissScreen")
}

/// Tells the delegate that a user click will open another app (such as
/// the App Store), backgrounding the current app.
func adViewWillLeaveApplication(_ bannerView: FADBannerView) {
  print("adViewWillLeaveApplication")
}

/// Tells the delegate an ad request loaded an ad.
- (void)adViewDidReceiveAd:(FADBannerView *)adView {
  NSLog(@"adViewDidReceiveAd");
}

/// Tells the delegate an ad request failed.
- (void)adView:(FADBannerView *)adView
    didFailToReceiveAdWithError:(FADRequestError *)error {
  NSLog(@"adView:didFailToReceiveAdWithError: %@", [error localizedDescription]);
}

/// Tells the delegate that a full-screen view will be presented in response
/// to the user clicking on an ad.
- (void)adViewWillPresentScreen:(FADBannerView *)adView {
  NSLog(@"adViewWillPresentScreen");
}

/// Tells the delegate that the full-screen view will be dismissed.
- (void)adViewWillDismissScreen:(FADBannerView *)adView {
  NSLog(@"adViewWillDismissScreen");
}

/// Tells the delegate that the full-screen view has been dismissed.
- (void)adViewDidDismissScreen:(FADBannerView *)adView {
  NSLog(@"adViewDidDismissScreen");
}

/// Tells the delegate that a user click will open another app (such as
/// the App Store), backgrounding the current app.
- (void)adViewWillLeaveApplication:(FADBannerView *)adView {
  NSLog(@"adViewWillLeaveApplication");
}

# 6.3 Use cases

Here are some example use cases for these ad event methods.

  • Adding a banner to the view hierarchy once an ad is received

You may want to delay in adding a FADBannerView to the view hierarchy until after an ad is received. You can do this by listening for the adViewDidReceiveAd: event:

func adViewDidReceiveAd(_ bannerView: FADBannerView) {
  // Add banner to view and add constraints as above.
  addBannerViewToView(bannerView)
}
- (void)adViewDidReceiveAd:(FADBannerView *)adView {
  // Add adView to view and add constraints as above.
  [self addBannerViewToView:self.bannerView];
}
  • Animating a banner ad

You can also use the adViewDidReceiveAd: event to animate a banner ad once it's returned, as shown in the following example:

func adViewDidReceiveAd(_ bannerView: FADBannerView) {
  bannerView.alpha = 0
  UIView.animate(withDuration: 1, animations: {
    bannerView.alpha = 1
  })
}
- (void)adViewDidReceiveAd:(FADBannerView *)adView {
  adView.alpha = 0;
  [UIView animateWithDuration:1.0 animations:^{
    adView.alpha = 1;
  }];
}

# 7. Test

Please use the test Ad Unit ID for you test

  • adUnitId: Fascode-Ads-Test-AdBannerId