The course is part of this learning path
This course explores how to enable push notifications in your iOS apps. We're going to walk you through how to do that using an Instagram clone that we created in a different course.
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 section, we're going to learn how to implement push notifications in our apps. In order to do that, I'm going to use the Instagram clone that we have made in the previous section because it's so convenient. We have a like functionality over here and when we hit on like, we want to display a push notification to the post owner, so that post owner will see a push notification in his or in her phone saying that somebody liked your post. For example, if you are using this with James, then if Kirk likes James post, James will see a push notification indicating that Kirk has liked your post. So, that when James hits on that push notification, it will open his app and we will have a complete push notification solution in our Instagram clone. Of course, you can try this with another app or you can create an app just to try this as well, but this is so convenient so I'm going to go with this. We don't even need Instagram or we don't even need Firebase in order to make this work. But anyway, I'm going to use this as an example, so if you haven't watched the Instagram clone section, I really suggest you go back and watch this to understand how this works. And second thing, in order to test push notifications, you have to have an iPhone device and you have to have a developer account. So, in order to upload your apps to the app store and in order to test some features like push notifications, you have to have a developer account and it costs $100 annually. So, if you're not ready to put your app on the app store or if you don't want to try and test push notifications, maybe you don't want that. But if you're ready and if you really want to implement this in your app, then I suggest you come over here to developer.apple.com and under account, you can create your own developer accounts. Okay. Again, it costs 100 bucks so it's kind of expensive but if you're going to be an IOS developer, you will need one. Of course, if you're working for a company, you can use your own company's Apple ID as well. So, this is how we go to developer.apple.com and just sign in our developer account. Once you hit the account tap, it will ask you for your apple ID and password. You can just give these credentials and open this dashboard where we will adjust our push notification settings. Okay. And again, if you don't want to test this but if you want to learn how push notifications work, you can actually watch this section to understand how these push notifications is implemented but you cannot test it without an apple developer account. So, first of all, I'm going to show you what we will use in order to implement push notifications and the tool that we're going to use is called One Signal. Okay. So, if you come to onesignal.com, so this is a platform, this is a tool that actually gives you a tool to use for free and you can just send as many as push notifications you want from your apps using this One Signal. So, this is a great tool and big companies use this tool and it's completely free so why not we use it. Right. So, we can use this with IOS apps, we can use this with android apps and we can even use this with web push notifications as well. So, if you're building an app that works on some other platforms then this One Signal will be the choice for you. I'm going to show you how to work with this tool, how to set this up and how to do all procedures in order to get this work. Don't worry. So, after you come to your onesignal.com, you have to create an account which is fairly easy. So, come over here and find log in or sign up. So, I have an account, so I'm going to log in but in your case, you have to click on the sign up and provide some email address, some password and your name or your company's name and just hit create account. And after you sign up, you can just come over here to sign it. And as you can see, it says that no credit card required because it's completely free. So, let me log in from here and as you can see, I'm already logged in and I can see all my applications in this list. So, I have some test applications over here and I can add a new one and I can delete the existing ones or I can adjust the existing settings. So, let me add a new app and in our case, our app will be called InstaCloneFirebase. Okay. Once I add this app, it will ask me to do some configurations and we're going to start with choosing our platform. So, as you can see, it works on a lot of platforms and of course, we are interested in Apple IOS at this point. So, I'm going to go for Apple IOS but in any case, if you're working with other platforms, you're more than welcome to do it later on. So once I choose the Apple IOS, it will ask me to configure this platform and it will ask me to create a P12 file. So, this is a production certificate for push notifications. Okay. So, we have to create this file first and in order to create this file, we need a developer account. Okay. So, that's why we need a developer account. So, I'm going to show you how this works. So, if you can come over here to read the documentation, you can follow along the documentation and guides as well in order to create yours. I'm going to open it anyway and I'm going to show you how to do it manually as well. So, you have to go to your developer account and open it first of all, and come back here to read the documentation. As you can see, they have an automatic provisioning tool as well. So, if you give your Apple ID and password over here, it can create all these things for you. But I'm not going to do that, I'm just going to do it manually in case it fails or in case if you don't want to give your credentials to One Signal. So, I'm going to show you how to do that manually because if you do it manually, it will work in every case. So, first of all, we're going to need something called certificate authority. It's actually called a CSR, certificate signing request. So, in order to do that, we have to access something called key chain access and we have to come over to this menu and say request a certificate from a certificate authority. So, maybe you have never worked with key chain access before. It's kind of a tool that we store every password, every certificate in our MacBooks. In order to reach that, you have to hit command and space in your keyboard and write key chain access. So that's the one that we are looking for. So, let me minimize this and let me just move this a little bit further. So here, we see all the logging related things in our MacBook. Remember, we have to request a certificate from a certificate authority. So, if you come over here to certificate assistant, you will see some different menu over here. So, it's not saying request a certificate from authority. It says that request a certificate with your user name. So if you see something like that, you have to click something else rather than all items or login. So, try to click on system or system route, for example. As you can see, it still doesn't work but if I click over here to system route and let's try it one more time. Come over here to key chain access and certificate assistant, now you will see request a certificate from a certificate authority. That's what we want. Now if I click on this, it will ask me for my email address and my name. So over here, you have to give your developer account email address and your name or your organization name and over here choose save to disk. So after doing that, you will just hit continue and it will create the CSR for you. So certificate signing request, that's what we need in order to create some certificates later on. So after you do that, you can just close this down and go back to your developer account. So in the documentation, it explains how to do that actually and over here, as you can see, there are some other things to do in the developer account and it actually explains all of them but I'm going to show you anyway. First of all, we need to come to the certificate identifiers and profiles. Over here, we will see the identifiers. So, this is where we register our app. It's registering your Bundle ID to your developer account. And as you can see, it says that do not enable push notifications in that phase. I'm going to show you how to enable push notifications later on, don't worry. So, come over here to Identifiers. As you can see, our app is not listed over here, and we need its Bundle ID in order to register it. So, come over here to General and try to copy this bundle identifier, okay? So, let me go back and let me see if we have this over here. Nope, we don't have it, so then we have to bring in manually, okay? All we have to do is just come over here to + sign and hit the '+' to create our new bundle identifier. So, let me hit over here. And as you can see, it asks for some options, and we need one app ID, okay? So, we have other kind of identification as well, but we need to register our app, so I'm choosing app ID. And over here, we need to give this Bundle ID that we have copied. So, let me copy it one more time just to be sure with Command C, and let me bring this down and paste it over here with Command V. And here you have to write a description for your app. I'm just going to name this InstaCloneFirebase as it is, okay? And then later on we see these capabilities over here as shown in the documentation, I'm not going to enable this at this phase, but later on I'm just going to enable this inside of Xcode. So, once you give that, you can just come over here to this menu and register your app. It means that your Bundle ID is registered to your developer account. So, now you can see InstaCloneFirebase in that list. So far so good, now we have registered our app and if I hit on that, I can see it, I can remove it, I can just see the Bundle ID and other Apple ID profile, numbers, and everything, okay? So, as shown in the documentation, I'm going to come over here and say push notifications is enabled, but I'm not going to configure it because we're going to do that inside of XCode as I've said before. As shown here, you have to enable this but not configure it, okay? So, next thing will be to create a new certificate, that's what we are looking for, actually. We're going to do that in the developer account as well, so I'm going to show you where it is, but as you can see, it's under Services and Apple Push Notification service SSL. So, let me go back to my developer account after enabling this but not configuring it, let me confirm this, save this, and just go out of this identifier section. Let me check if it's enabled. Yes, it's enabled. Okay, it's saved. So, let me go back and create our certificate. So, in here we're going to go for certificates, and over here we're just going to add a new certificate, okay? As you can see, you see my existing certificates, but we are looking for a new Apple Push Notification service and APNs SSL certificate, okay? So, we are looking for that. So, come over here and hit the '+' button, and over here we will see something like services. And under the services, we have some options: you will see iOS Apple Push Notification service and you will see Apple Push Notification service SSL, so we need Apple Push Notification service as described in the documentation. Okay, because this is for production, so let me come over here, and you will see to select Apple Push Notification service SSL. So, after choosing that, you can just continue and create your certificate. It will ask you for an identifier. And since we have registered our app, we can easily choose that identifier. So, let me choose InstaCloneFirebase, okay? So, I believe that's it. After choosing my app, I can register, I can create a certificate just for that app, so it asks me to provide a CSR in the step as you can see, that's why we have created this CSR in the first place. So, since now I have that, I'm going to say choose file, and I'm going to go over to my desktop where I can find the CSR and just choose it. So, this will actually provide the proof that I'm really the developer that is trying to sign this app. After that you can just download your certificate. And as you can see, now we have this .cer file, so this is our certificate, okay? And let me go back to documentation because we have a lot more things to do. After downloading this, as you can see, we have to bring this in to the Keychain, and then we have to create a provisioning file which we will upload to the one signal. So, let me show you how this goes, let me open Keychain Access one more time. And over here under My Certificates, I'm going to bring in the certificate that I have created, okay? So, let me bring this down a little bit, let me go to login and My Certificates, so choose login from Keychains, and in the category, choose your certificates, okay? So, that you can see all the certificates related to you and your apps. After that, we have to bring in the newly created certificate and say export Apple Production Push services. So, let me try to do that. We're going to need our newly brought in CER. So, if you double-click on that CER, it will appear in here. So, if you cannot see it over there, you can just double-click, or you can bring this in manually, so let me try to do that. So, if I double-click on this, it will be displayed in the Keychain, or I can just bring this in like dragging and dropping as you can see. Now, let's see which one, I believe that's the one that we're looking for, InstaCloneFirebase. So, right now I can come over here and right click and say export Apple Push Services, and it will create a p12 file for me. So, I'm going to name this myInstaClone. And as you can see, this is p12 and that's the one we were looking for all the way along, right? So, now I can just save this, and I can just upload this to the OneSignal. I'm going to save this on my desktop so that we can each it reasonably, and it will ask me for a password. We're going to use that password later on, so make sure you remember what password you're giving right now, because OneSignal will ask us to provide that password, okay? Once you do that, you can just hit on 'OK' to create this. And let's say 'OK', and then it will ask you for your Keychain Access export key. So, this is the password for your own computer. So, let me write my password, okay? So, this is the password for my own MacBook. If I say hello, it will create the certificate for me. So, here you go. Now I have created my p12 file. So, now I can go over to my OneSignal configuration, and I can just upload this production certificate over here. So, let me choose that file, okay? And let me go to my desktop, that's the one that we're looking for. So, when we upload this, it will ask us to provide the password that we have just given. And if you don't remember your password, you have to do all of those things from scratch, so make sure you take note of your password, okay? And after you provide this password, you can just say 'Save' and move along with your configuration. So, this has been a long lecture. Let's stop here and do the rest of the things in the next lecture.
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.