Make Money from Your Apps
The course is part of this learning path
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.
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 load the ad so that we can actually show it to the user later on. So far we have installed the pod and we have actually set up our application so that we are ready to go and implement the next step. So, we have done the pod install section, okay? Of course, you can do just repo update or anything you want if your pod doesn't work at this point but I believe it's okay, so let's go to the next step. So, in the update your Info.plist section, right now I'm in the AdMob. Okay, I can just come over here and just do it under the Ad units as well. However, I'm still in the documentation section which is developers.google.com, okay? We have implemented the GAD application identifier which is our publisher identifier and we switch back to testing. So, I'm in the test section but again, it asks me to give these keys and IDs, so these are complicated values that we need to integrate into Info.plist and we're going to talk about what those do. Basically, what they do actually is that they get the necessary ad from the network of Google, okay? So, we're going to have to just come over here and we see the GADApplicationidentifier is already embedded in here but also we need to get this Ad network items and just embed them here as well. So, there are a bunch of values and they are in the shape of dictionaries and arrays, so it can get complicated to integrate all of this. So, what I'm going to do, I'm going to copy every one of keys over here and just paste them into the Info.plist and I'm going to show you how to do that. So, for some reason I cannot copy only the key since we have integrated GADApplicationidentifier, we need to be careful but I'm just going to copy them all. Okay, just copy them all by clicking over this copy code sample and come back to XCode. So, if you want to change this to like an XML layout, then come over here and say open as and choose this source code. If you choose this source code, as you can see right now we see the Info.plist as an XML file. So, at the beginning of this XML file, we see that GADApplicationidentifier and string is already here, so what I'm going to do, I'm going to come over here and hit 'Enter' and I'm going to paste the thing with command V, and here we go. Now it's in here. Of course, we have to get rid of one of these because it's duplicated right now. So, I'm going to just delete one of this and come back to Info.plist. So, that's it. That's all you got to do to include all the ad network identifiers over here, and we're going to talk about what those do in that later on. Now I'm going to go back to property list, okay? And here we go, now it's back. It's all good right now and as you can see it's pretty complicated. It may take a lot of time to just embed this one by one but if you copy and paste these things then it's okay. Then I'm okay, now I'm going to go back to ViewController Swift. So, for some reason we're going to have to just make sure that this next click works because as you can see there is an emptiness over here, I'm going to just print something to see if this next click button is working right now. I believe there is some a buck in my case and let me see if I can click on that next click button. If you don't see that issue then don't worry about this at all, but I just want to make sure that it's working or not. So, as you can see it doesn't work, I cannot click on that next button. Most probably it's an outlet issue. It can be a constraint issue as well. So, if you come across in this case, a case like this, you're going to have to go to main storyboard and find the outlet inspector connections. Inspector like this, and break the connection that you have created with this. Once you do that, you can go back to ViewController and just delete this line and then connect it back later on. Now, I'm going to do that. I'm going to open an editor over here and go to main storyboard. Again, if you didn't come across this situation then don't worry about it at all. But I'm just going to make this right, I'm going to bring the next button over here and I'm just going to call this next clicked. And here we go. Now, it seems fine but I want to make sure I'm just going to print something again, like print clicked and just run this to see if this works or not. If this doesn't work, then it should be a constraint issue. Now, let's wait until it appear over here and here we go, I cannot click it again. So, most probably it has something to do with the constraints themselves. So, I'm going to click on this and say clear constraints and I'll give the same constraints. I'm going to make this a little bit bigger, okay? Maybe we can just give horizontally and vertically constraint with zero values. Maybe we can do this a little bigger and put this in the middle one more time. I just messed this up a little bit, I'm going to say update the constraint constants and here we go. Now, let's see, it really doesn't matter how it looks like, all I want to do is just to be able to click on that button. Okay, let's try this and see if that works or not. So, I'm going to click on this and here we go. Now it's working. Great. Now, I'm going to stop this and now we are certain that we can just write the code under this next click. So, I'm going to go back to the documentation and here we go. It asks me to initialize the mobile ads SDK. Since we have downloaded this pod and we integrated it, now we're going to have to just make sure that it's initialized once our application is running. So, it asks me to go to appDelegate and import the Google mobile ads SDK and then run this GADMobileAds.sharedInstance.start. Of course, these codes can change in time, you're going to have to follow the documentation like I'm doing right now. So, I'm going to import this GoogleMobileAds and find the didFinishLaunchingWithOptions. It should be the first function that comes within the appDelegate itself, okay? This one. So, I'm going to copy and paste this, and here we go. Now it should be ready to go, right? It looks good. Of course, this is just a simple initialization code, so we have done this numerous times so I'm going to just cut this short. So, after that we're going to have to create an ad format or choose an ad format. We can do this over here or from the AdMob account itself, okay? So, I'm going to talk about this differences a little bit as you can see there is a banner choice which displays a banner at the top of the or at the bottom of the application. So, it's generally like a banner ad but this interstitial is the most commonly used one. It displays a full screen ad, but you have to use it if there is something like a screen change or maybe a level change in a game or something like that where user can expect to see or may expect to see some kind of a full screen ad. It's most commonly used ad so I'm going to demonstrate this example. Of course, they all have different kind of codes that you can find in the documentation and for the native one, it's actually a customizable ad. So, you can customize this ad to show it in your application. And rewarded ads are ads that we use in games for example, when we deal with unity or stuff. So, it's kind of do this and I'm going to give you something like maybe an item in a game and in return you're going to have to watch a video. So, we're going to focus on the interstitial ads as I said before because it's commonly used in the mobile application industry, I'm going to just click on the implement section. So, first of all, as you can see you can see all the documentation over here. Before implementing that, of course, you can come back to your AdMob account and just say get started and see all the options over here as well. Eventually, you're going to have to create an ad from here, okay? For example, you can just give any ad name like first ad or something like that and when you do that it will give you an ad ID. So, this is your publisher ID, real ID the one we got rid of from the Info.plist and I replaced it with the test. And of course, don't forget to just change it back when you're releasing the application but this one is the ad unit ID. So, this ID is specific to the ad that we have just created. So, you can use this ID for that specific interstitial ad. So, if you ask that I want to just create one unit ID and I want to use that unit ID with every interstitial ad that I'm going to be displaying in this application, it's totally fine. It will work but Google doesn't actually recommend that. Google recommends that you create different IDs for different ads in your application so that you can actually track the performance better, so you can make decisions about your ad choices, okay? So, don't forget to take this and just take a note for that. Okay, this is your real ad ID. So, not this one but from here. So, this is your real ad ID. So, you're going to have to change this from test ID to the real ID when you're releasing that application in the App Store. So, take a note of that. But again, of course, I'm just going to click done and just go with the documentation and just follow along with the test ad. So, this is our ad ID. Of course, you can come over here to implementation instructions but it will just lead you to the documentation that we are currently viewing. Okay, this one. So, again, we're going to land here eventually. So, I'm going to follow along with this one. As you can see it gives me a test ID as well for this implementation for this interstitial ad. I'm going to take this one and just take a note that this is a test ID and just paste it over here, okay? So, this is the real ID and this is the test ID. Don't forget to switch back to the real ID once you're done with your application. Now I'm going to of course use the test one to test it on the debug, okay? Real IDs only work after you publish your application actually. So, there are three steps, you load the ad, you register for the callbacks. So, this is to manage the events. We're going to see what it is and then we're going to display the ad to the user. They are all very basic, all you got to do is just follow up the documentation or follow along with the documentation over here. In this lecture, let's take care of loading the ad then we can display the ad to the user in the next lecture. So, for loading the ad, of course, it has different documentation for different kinds of ads. Right now we are in the interstitial section, so I'm going to go along with this. I'm going to import the GoogleMobileAds library over here, okay? And loading the ad is not the same with displaying the ad, okay? We just get the ad content from the network once we do that. So, as you can see under class, it says that create your private var interstitial ad which is GADInterstitialAd, okay? I'm just copying and pasting it. So, I recommend you do the same thing as well because it changes frequently, so you're going to have to follow along with the documentation. I'm doing the loading thing under viewDidLoad and as you can see we are creating a request object and this request object is used along with this library that we have imported and GADInterstitialAd is again class that we can import from that library as well. And this is the test ID as you can see, it comes with the documentation as well. I'm not going to change it because we're going to use test, so I'm going to just cut and paste this over here and we are using the test ID with the request that we have created. It has a completion handler. It shows if there's an error not and if there's an error, it displays the error message. But if there isn't any error, it just make this interstitial ad equal to ad itself and this ad is coming from this completion handler to us. That's how we actually load the ad itself. But we are not yet displaying to the user, we're going to take care of that within the next lecture together.
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.