In order to display advertisements, you need to enable SDK first. For details, please refer to Installing Guide and Initializing the SDK
A precondition for simple In-Feed advertisements is use of UITableView.
For other uses, use Customized In-Feed advertisements.
Here is an implementation example of simple In-Feed advertisement.
class YourViewController: UITableViewController, RFPInstreamAdLoaderDelegate {
let adSpotId = "your_adspot_id"
let adPositions = [3, 5]
let instreamAdLoader = RFPInstreamAdLoader.init()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
// Set the tableView and adspot ID for which you wish to insert the In-Feed advertisements
instreamAdLoader.delegate = self
instreamAdLoader.rfpBind(to: tableView, adSpotId: adSpotId)
// Loading In-Feed advertisements
instreamAdLoader.rfpLoadAd()
// Case specifying the positions
instreamAdLoader.rfpLoadAd(UInt(adPositions.count), positions: adPositions)
}
//....
}
There is no need to call tableView.reloadData(). If it is necessary to call tableView.reloadData(), call instreamAdLoader.rfpReloadData().
The number of advertisement cases and the advertisement position array per request can be controlled using APIs, such as instreamAdLoader.rfpLoadAd(_:positions:).
When displaying In-Feed advertisements, you may choose to receive these events.
In this case, since the RFPInstreamAdLoader property delegate conforms to RFPInstreamAdLoaderDelegate, it may be received via RFPInstreamAdLoaderDelegate
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 advertisement View loading
func rfpInstreamAdLoaderDidFinishLoadingAdImage(_ adIndexPath: IndexPath!) {
}
//(5) When completing advertisement click processing
func rfpInstreamAdLoaderDidFinishSendingAdClick() {
}
//(6) When advertisement loading fails
func rfpInstreamAdLoader(_ instreamAdLoader: RFPInstreamAdLoader!, didFailToLoadAdWithError error: Error!) {
}
//(7) When advertisement View loading fails
func rfpInstreamAdLoader(_ adIndexPath: IndexPath!, didFailToLoadAdImageWithError error: Error!) {
}
In the case of a UI that loads additional feeds when the user arrives at the bottom of the site, it is possible to provide additional loading of advertisements.
func loadMore {
// Load additional advertisements and insert them at appropriate positions in the table based on the advertisement position array.
instreamAdLoader.rfpReloadData()
}
Currently, seven advertising formats may be used. Settings are here.
// The format looks like this
// -----------------------------------------------------
// | | name |
// | image | ad text |
// | | |
// | 90x90 | |
// | | PR |
// -----------------------------------------------------
// The format looks like this
// -----------------------------------------------------
// | ------- name |
// | | image | PR |
// | | 50x50 | ad text |
// | | | |
// | ------- |
// -----------------------------------------------------
// The format looks like this
// -----------------------------------------------------
// | |
// | ad image |
// | |
// | --------------------------------------------------- |
// | ad text |
// | |
// | |
// | PR |
// | advertiser name |
// -----------------------------------------------------
// The format looks like this
// -----------------------------------------------------
// | advertiser name |
// | PR |
// | ad text |
// | --------------------------------------------------- |
// | |
// | |
// | image |
// | |
// -----------------------------------------------------
// The format looks like this
// -----------------------------------------------------
// | name |
// | PR |
// | --------------------------------------------------- |
// | |
// | |
// | image |
// | |
// | |
// | |
// | --------------------------------------------------- |
// | text |
// -----------------------------------------------------
// The format looks like this
// -----------------------------------------------------
// | name |
// | PR |
// | --------------------------------------------------- |
// | |
// | ad text |
// | |
// | |
// -----------------------------------------------------
The operation of UITableView passed to instreamAdLoader.rfpBind(to:adSpotId:)is only guaranteed when the number of sections is 1.