Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook native Ads are not clickable again in UITableView Cells after scroll

I have implemented facebook native Ads in UITableView, for first 1-2 times it clickable but when I scroll tableview and come again back to the same cell, now Ads are not clicking, I am using swift 3.2 Below is the cell implementation.

let ad = adsManager.nextNativeAd
let cell = self.tableHome.dequeueReusableCell(withIdentifier: "HomeAdsTableViewCell", for: indexPath) as! HomeAdsTableViewCell
cell.message.text = ad?.body
cell.title.text = ad?.title
cell.callToActionButton.setTitle(ad?.callToAction, for: .normal)

if let pic = ad?.coverImage {
    cell.postImage.setImageWithIndicator(imageUrl:pic.url.absoluteString)
}

ad?.registerView(forInteraction: cell.postView, with: self)
cell.selectionStyle=UITableViewCellSelectionStyle.none

return cell
like image 348
Saurabh Singh Rathore Avatar asked Jun 09 '18 05:06

Saurabh Singh Rathore


2 Answers

//create a new object  of nativead in your class//

var previousNativead : FBNativeAd?

let ad = adsManager.nextNativeAd
self.previousNativead?.unregisterView()
let cell = self.tableHome.dequeueReusableCell(withIdentifier: "HomeAdsTableViewCell", for: indexPath) as! HomeAdsTableViewCell
cell.message.text = ad?.body
cell.title.text = ad?.title
cell.callToActionButton.setTitle(ad?.callToAction, for: .normal)

if let pic = ad?.coverImage {
    cell.postImage.setImageWithIndicator(imageUrl:pic.url.absoluteString)
}
previousNativead = ad
ad?.registerView(forInteraction: cell.postView, with: self)
cell.selectionStyle=UITableViewCellSelectionStyle.none

return cell
like image 83
thirthankar Pal Avatar answered Nov 15 '22 00:11

thirthankar Pal


I suggest you follow the steps here. He told me about putting a facebook ad between cells.

https://www.appcoda.com/facebook-ads-integration/

It's like you do not make mistakes in the place you turn the idiot.

You should adapt this part in the link to your own.

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
       if adsCellProvider != nil && adsCellProvider.isAdCellAtIndexPath(indexPath, forStride: UInt(adRowStep)) {
         return adsCellProvider.tableView(tableView, cellForRowAtIndexPath: indexPath)
       }
       else {
         let cell = tableView.dequeueReusableCellWithIdentifier("idCellSample", forIndexPath: indexPath) as! SampleCell
         cell.lblTitle.text = sampleData[indexPath.row - Int(indexPath.row / adRowStep)]
         return cell
       }  }

You should also use this method on screen refreshes and turns.

    func configureAdManagerAndLoadAds() {
      if adsManager == nil {
        adsManager = FBNativeAdsManager(placementID: "PLACEMENT_ID", forNumAdsRequested: 5)
        adsManager.delegate = self
        adsManager.loadAds()
      }}
    override func viewWillAppear(animated: Bool) {
      configureAdManagerAndLoadAds()}

Finally you should check the relevant fields, which may not be compatible with content swift 3.

like image 39
Resul Rıza Dolaner Avatar answered Nov 15 '22 01:11

Resul Rıza Dolaner