When you want to display with more flexibility than with simple In-Feed advertisements, you can use customized In-Feed advertisement functions.
In order to display advertisements, you need to enable SDK first. For details, please refer to Installing Guide and Initializing the SDK
Upon implementation, be sure to include text so that the user recognizes and understands that the locations in which advertisements appear are, in fact, advertisements.
(Example: “PR”, “Sponsored”, “Ad”, “Advertisement”)
displayedAdvertiser
, appropriate text for each advertisement can be displayed.The following guide shows an example based on UITableView
, but it may be used in other cases such as UIView
.
Here is an implementation example of customized In-Feed advertisement.
class YourViewController: UIViewController, RFPInstreamAdLoaderDelegate {
let instreamAdLoader = RFPInstreamAdLoader.init()
let adSpotId = "your_adspot_id"
let positions = [0, 1, 2]
override func viewDidLoad() {
super.viewDidLoad()
// Set the delegate
instreamAdLoader.delegate = self
// Call In-Feed advertising loading
instreamAdLoader.rfpLoadAd(
withReturn: adSpotId,
adCount: UInt(positions.count),
positions: positions
)
}
// Complete In-Feed advertisement loading
func rfpInstreamAdLoaderDidFinishLoadingAd(withReturn instreamAdLoader: RFPInstreamAdLoader!, instreamInfoModels: [Any]!) {
// Receive the In-Feed advertising information
for model: RFPInstreamInfoModel in instreamInfoModels as! [RFPInstreamInfoModel] {
items[model.position.intValue] = model
}
// Update the display
tableView.realoadData();
}
}
You can specify custom parameters when loading in-feed ads.
// Call In-Feed advertising loading
instreamAdLoader.rfpLoadAd(
withReturn: adSpotId,
adCount: UInt(positions.count),
positions: positions,
customs: ["a": "1", "b": ["2", "3"]]
)
// custom[a]=1&custom[b]=2&custom[b]=3
Display the advertisements based on the information acquired from RFPInstreamInfoModel
. As position
is used in the advertising results analysis, use this as reference when determining the position within the screen.
if (model.title) {
titleLabel.text = model.title
}
if (model.content) {
contentLabel.text = model.content
}
model.rfpLoadImage(imageView, completion: { error -> Void in
print("Load Finish.")
if (error != nil) {
print("Load Error.", error!)
} else {
instreamAdLoader.rfpMeasureImp(model)
}
})
When display of advertisements is complete, notify the impressions.
Call RFPInstreamAdLoader.rfpMeasureImp(_:)
.
// model: RFPInstreamInfoProtocol!
RFPInstreamAdLoader.rfpMeasureImp(model)
When the advertisement is clicked, user is appropriately transitioned by calling the following method.
Call RFPInstreamAdLoader.rfpSendClickEvent(_:)
.
// model: RFPInstreamInfoProtocol!
RFPInstreamAdLoader.rfpSendClickEvent(model)
Acquires characters displayed on the button (user action) set from the management screen using RFPInstreamInfoModel.getCtaText()
.
func rfpInstreamAdLoaderDidFinishLoadingAd(withReturn instreamAdLoader: RFPInstreamAdLoader!, instreamInfoModels: [Any]!) {
for model: RFPInstreamInfoModel in instreamInfoModels as! [RFPInstreamInfoModel] {
// Acquiring the button display characters
// - "See here for details"
// - "Reserver"
// - "Purchase"
// - "Register" ....
print("Button Name", model.getCtaText())
}
}
There are times when you will wish to receive this event, when loading In-Feed advertisements or giving each notification.
In this case, the delegate property in RFPInstreamAdLoader
conforms to RFPInstreamAdLoaderDelegate
, and can be received.
If using Library Support for Viewable Impression to track viewable impression, impression’s results would be sent from the library.
override func viewDidLoad() {
super.viewDidLoad()
// (1) Set delegate
instreamAdLoader.delegate = self
}
// (2) When starting advertisement loading
func rfpInstreamAdLoaderDidStartLoadingAd(_ instreamAdLoader: RFPInstreamAdLoader!) {
}
// (3) When completing advertisement loading
func rfpInstreamAdLoaderDidFinishLoadingAd(_ instreamAdLoader: RFPInstreamAdLoader!) {
}
// (4) When completing notification of advertisement impression
func rfpInstreamAdLoaderDidFinishSendingAdImp() {
}
// (5) When completing advertisement click processing
func rfpInstreamAdLoaderDidFinishSendingAdClick() {
}
// (6) When advertisement loading fails
func rfpInstreamAdLoader(_ instreamAdLoader: RFPInstreamAdLoader!, didFailToLoadAdWithError error: Error!) {
}
// (7) When advertisement impression notification fails
func rfpInstreamAdLoader(_ instreamAdLoader: RFPInstreamAdLoader!, didFailToSendImpWithError error: Error!) {
}
// (8) When advertisement click processing fails
func rfpInstreamAdLoader(_ instreamAdLoader: RFPInstreamAdLoader!, didFailToSendClickWithError error: Error!) {
}
// (9) Video advertisement playback preparation complete
func readyToPlay(with playerControl: RFPPlayerControl!) {
}
// (※)Compulsory when playing back video advertising
func viewControllerForPresentingModalView() -> UIViewController! {
return self
}
Also refer to RFPInstreamInfoModel.h
.
parameter name | description | example |
---|---|---|
title | Title text (20 full-sized chars max) | TestAd |
content | description/introductory text (40-70 full-sized characters) | test advertisement. |
position | advertisement case relative position | 3 |
displayedAdvertiser | displayed advertisement name | beverage company A |
imageURL | banner-type square images (variable size for each advertising framework ID) resources | NSURL objects |
creativeSize | Size of banner image (or video advertisement) | CGSize objects |
RFPInstreamInfoModel.rfpLoadImage(_:UIImageView!,completion:((Error!) -> ())!)
RFPInstreamInfoModel.getAdId()
when acquiring the advertisement ID.Currently, seven advertising formats can be used freely. This is the UITableViewCell
sub-class.
The required files for using the default advertising format are as follows.
RFPInstreamAdCellThumbnailMiddle.h
RFPInstreamAdCellThumbnailSmall.h
RFPInstreamAdCellLandscapePhoto.h
RFPInstreamAdCellPhotoBottom.h
RFPInstreamAdCellPhotoMiddle.h
RFPInstreamAdCellTextOnly.h
RFPInstreamAdCellWebView.h
Choose the format to use from among those above
It is possible to use formats that can be used from simple In-Feed advertising.
Set the header of the format in Bridging-Header.h to use in advance.
#import <RFP/RFPInstreamAdCellThumbnailMiddle.h>
Implement as follows to display the default advertising format.
override func viewDidLoad() {
super.viewDidLoad()
// Register the class of the ad format you want to use in advance
self.tableView.register(RFPInstreamAdCellThumbnailMiddle.self, forCellReuseIdentifier: "adCell")
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let model = items[indexPath.row]!
// Extract the advertising format class registered in advance
let cell = tableView.dequeueReusableCell(withIdentifier: "adCell", for: indexPath) as! RFPInstreamAdCellThumbnailMiddle
// Depict the cells based on the loaded advertising information
cell.rfpUpdateCell(model, completion: { (error) -> () in
// After depiction is completed
print("Updated Cell")
})
return cell
}
By using RFPExceptionDelegate
, exceptional contents occurring within SDK may be acquired.
Please refer to Error code description for details.
class YourViewController: UIViewController, RFPInstreamAdLoaderDelegate, RFPExceptionDelegate {
let instreamAdLoader = RFPInstreamAdLoader.init()
let adSpotId = "your_adspot_id"
let positions = [0, 1, 2]
override func viewDidLoad() {
super.viewDidLoad()
// Set delegate
instreamAdLoader.exceptionDelegate = self
// Call In-Feed advertising loading
instreamAdLoader.delegate = self
instreamAdLoader.rfpLoadAd(
withReturn: adSpotId,
adCount: UInt(positions.count),
positions: positions
)
}
// Exception content acquisition Delegate
func exceptionOccurred(_ error: Error!) {
print("exceptionOccurred", error)
}
}
In iOS 13.0 and later, users can choose to adopt a dark system-wide appearance called Dark Mode. Please ensure that advertisements can be recognized in both modes.
Please see Human Interface Guidelines/Dark Mode for the details about Dark Mode.