Displaying Ads
Start course

This course will show you how we can make money out of your apps. We'll explore the alternative ways to make money using IOS development as well as how to use Google advertisements in your app so that you can earn money with Google ads.

Intended Audience

This course is designed for anyone who wants to:

  • Learn about iOS development and coding
  • Move into a career as an iOS developer
  • Master Swift skills


To get the most out of this course, you should have some basic knowledge of iOS.


Hi, within this lecture, we're going to show the ad that we just have loaded to the user. So, before displaying the ad itself, we may or may not register for the callbacks, it's totally optional. So, what are the callbacks? So, callbacks are functions. So, it lets us handle the events, for example, if an ad fails to show, if an ad fails to display, then what should we do, or if an ad actually manages to display, what should we do or what happens after it is dismissed. So, if you want to handle all of these situations, now you're going to have to follow along with this and just override these functions or just implement these functions. Okay, as you can see, one of them is called didFailToPresentFullScreenContentWithError or Ad did dismiss or Ad did present. So, these functions actually change over time as well. So, I really suggest you just copy and paste these things, but I'm going to show you how to do this, right now. So apparently, first of all, we're going to have to make sure that this has some delegates, some kind of interstitial?.fullScreenContentDelegate = self. However, once we do that, it will give us an error. It will say that ViewController is not that delegate. So most probably, we're going to have to implement something like this. So GADFullScreenControllerDelegate. We're going to have to make sure put that coma and just copy and paste this thing, or you can just write it yourself, like GADFullScreenContentDelegate. Okay? Once you do that, this delegate thing will go away. The error will go away. And then, you can just implement all these functions. You can copy and paste this, and in the class itself, you can just paste those functions. If you want to do something with this, again, this is optional. So, if you don't want to handle these things, then you just don't do it. But if you want to handle, for some reason, then this is the way to go. I'm not going to do something over here, I'm just going to leave the prints as it is, so that we can see if they are working or not once we run this application, but right now, this is okay. So finally, last but not least, we're going to display the ad to the user, and in our case, we're going to display that under the next button clicked function. Okay? So, I'm going to copy and paste this stuff over here. So, as you can see, so this is optional right now in the GAD, and it's asking if the interstitial is not nil or is nil. So, this is why it is controlling that and if you copy and paste this stuff, let's see if this works or not. It seems to be working. There is nothing wrong with it. Nope, we get an error, it says that this is a optional. As you can see, value of optional type GADInterstitialAd? must be unwrapped. So, I believe we can put an exclamation mark over here, since we are controlling if interstitial is not nil, so it will be okay, and then we are good to go. I believe this should work right now. So, in fact, we can just test this. Build failed. Let's see if we have an error message over here. Let's see what is the error message. For some reason I put that slash over there, so after deleting this, I believe it should be okay. Let's run this one more time, and here you go. Now, I'm going to minimize all of those things, and let's see if we can actually see the ad itself. So, here you go. Now, we get another error over here. So, it says that Google Mobile Ads SDK was initialized without AppMeasurement. So, it's a weird thing, it doesn't appear in the documentation but I'm going to show you what I mean. So, as you can see, it leads us to this website. So, I'm going to open that up. As you can see, it says that update your Info.plist and that's exactly what we have done, right? We have copied and pasted this thing. So, we have copied and pasted the networks, we have copied and pasted the GADApplicationIdentifier, and that's it. We follow along with the documentation, yet it still doesn't work. And there is another link over here. At measurement framework there is another link over here, which will not work, okay? Even though it works, it will just redirect you to the same page, but you can just try it yourself to see if it works or not. As you can see, it doesn't even open. Okay, it doesn't work. So, what's the issue over here? We follow along with the documentation but we're getting this weird error. So, if you just copy and paste this error, the Google Mobile Ads SDK was initialized without AppMeasurement. By the way, there is a chance that you don't get this error at all. But if you get it, if you go to stackoverflow, some guy said that, Christian Liu, he said that GADIsAdManagerApp. You're going to have to add this to your plist. So, as you can see it's a Boolean value and it indicates that we are using these ads in our application. It was required before, maybe a couple of years ago, but sometimes it just resurfaces for some reason, I don't know whether it has to do something with the old SDKs or if it's a bug or not, but it doesn't appear in documentation, but if you do that then, it will resolve that issue. So, I'm going to do that. I'm going to come over here and just add this to my Info.plist. If you didn't get that error, just don't worry about it at all. So, we're going have to spell it ourselves, GAD with uppercase letters and IsAdManagerApp. So, just GADIsAppManagerAds... Nope, AdManagerApp, sorry. AdManagerApp, and beware of the uppercase letters, G-A-D, I, A, M and A. So, it's a Boolean value, okay? And the value is yes, not no. So, make sure you select yes from here. Here you go. After that, you can try to run this one more time, and see if that works or not. Let's try together. It should resolve this issue and again, if you didn't come across with that kind of situation, then don't worry at all. So right now, I believe it's working, the ad is loaded but if we click on here, and here you go. Now, we are displaying that to the user. So, ad is loaded and we are displaying that to the user. That's all you got to do. Now of course, the other ad sections have their own documentation as well. So, you're going to have to figure out yourselves. But there is a thing that came up with the functions over your callback functions. Let's see if they are working or not, here we go. Ad did dismiss full screen content, Ad did present full screen content. They are all working right now. They seem to be working, so it's okay. Now, we have seen what we have to see. However, there is another thing that we should consider or at least we should know, which is called App Tracking Transparency which came around, I believe, in 2021. So, we're going to have to see that topic as well, within the next lecture together.


About the Author
Learning Paths

Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.

Covered Topics