Adding the Facebook Native Ad API in iOS — UITableView

kisoth srinathan
Sep 3, 2018 · 3 min read

Hi folks, Welcome to the world of Monetization. When I was integrating Facebook native ad with android, I could get all guidances from Facebook developer portal. But when I was trying to integrate native ads for my iOS app I couldn’t get the guidance from Facebook developer portal. They have been provided guidance to integrate native ad for UIViewcontroller not for UITableView.

Here is the link of Facebook guide.

So, I started to develop by my own. So First of all, I inserted two TableViewCells and provided “identifier” as ‘mycell’ for my default cell and as “fbnativecell” for the facebook nativead cell.

Then after my tableview data loaded into the array I inserted the one Native ad for every five rows.

Now we can take a look into the UITableView Datasource Methods as cellForRowAtIndexPath, didSelectRowAtIndexPath, heightForRowAtIndexPath and if you allow users to edit the cell in the UITableView you should customize the canEditRowAtIndexPath also.

Here is the trick we have to use to differentiate the Nativead and our cell content. Objective C offers you the method of comparing classes as following.

if([FBNativeAd class] == [Notes[indexPath.row] class]) {}

Here what happens is when the item for particular indexpath row in the Notes NSMutableArray comes as FBNativeAd this if statement should come as true. So you can implement your custom codes for the FBNativeAd.

Now Let me show how I implemented those methods.

I wanted to return height for cells but in different values for mycell and fbnativecell. So What I did in heightForRowAtIndexPath method is.

Here, __FaceBook_Main_NativeAD_HEIGHT and __mycell_HEIGHT are constants which carry values as 250 and 120 respectively.

Like this I compared items in array and implemented each method.

didSelectRowAtIndexPath

And then If you are offering the user edit facility in the tableview you have to implement the following also.

canEditRowAtIndexPath

That’s all. Now you have successfully implemented Facebook Native Ad for UITabelView.

Thank you very much for the time you spent on my article.

Catch you with next article soon.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade