One Signal Integration

The course is part of this learning path

Start course
Difficulty
Intermediate
Duration
1h 25m
Students
13
Description

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.

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

Prerequisites

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

Transcript

Hi, within this lecture, we're going to continue our configuration so that we can bring in the OneSignal SDKs to our project. So far, we have uploaded our p12 file and we are ready to go and select the SDKs to download, okay? So, I'm going to say 'Save' and we forgot to give the password that I have mentioned in the previous lecture. So, remember we have created this p12 file with a password. So, come over here to Production Private Key section and make sure you give the exact same password that you have chosen. And then after you can just say 'Save' and over here, you have to choose your SDK, and in our case it's, of course, Native iOS, okay? And after that, you can just say 'Next' and it will ask you to install the SDK and it will give you an App ID. So, we're going to need that App ID as well. So, make sure you take a note of this, copy and paste it somewhere in your project as a note for example, because we're going to use it to enable the server and project connection. So, let me open the documentation for iOS SDK Setup. So, as you can see we have a lot to do in this lecture as well, because we're not going to just create a path file and it will take care of everything for us, but rather we're going to add a service extension. So, we have worked with this kind of thing before, right? So, we have created some kind of keyboard extension but this time it's going to be a push notification extension. So, come over here to 'File New' and rather than File, say Target because we're going to work with extension and we have worked with this custom keyboard extension before, but right now we're looking for this notification service extension, okay? So, you can do that by following this documentation. As you can see, it says that 'Please choose this notification service and then come over here and just give some name and the name should be OneSignalNotificationServiceExtension.' So, you have to give this exact same name because we're going to use it in code as well. So, let me just choose that name, copy it, and choose Notification Service Extension and paste it over here, and make sure the project and target is selected, and then you can just come over here and say Activate or Cancel. In fact, you can just say Cancel because we're not going to use this to run in our simulator, right? So, as you can see it now has this as a target but rather we just want our project to be target, our project to be displayed in the simulator, and in fact, if you come over here to documentation, you will see that it actually suggest you click on 'Cancel' rather than activating it, so that we won't deal with this problem. But it's fairly easy, you can come over here to your project and select the iPhone XR from here so that it will be reversed. So that's it, so now we have implemented this extension in our project and we can see the extension in menus, okay? Now let's continue. Come over here, and as you can see, it asks us to go into the signing and take care of this deployment target thing. And it suggests us to lower our deployment target to 10, but since we have 13 over here, I don't think we need to do that. Because we are already working with 13, we don't need to lower it to 10. I believe it suggests not to use it below 10. So, we're using it with 13 so it will be okay for us. So, I'm going to leave that as 13. And later on we're going to have to bring in this code in order to initialize the app. As you can see, there is an objective C and swift files over here, and we need to create that file and bring in this as it is. So, let me do that, let me open this extension. The file is already created for us, but we're going to delete everything inside of that extension and we're going to replace it with the given code. So, let's do that. Let me copy everything from here and select everything first. So, I believe we can do some command A or we can just hit 'Copy' over here so it will copy everything. So, I'm going to do a command A and delete everything from here and paste the codes in. So, that's what we're going to be using to connect our app to the One Signal. And as you can see we cannot import One Signal yet because we haven't downloaded the SDK case, that's what we're going to do now. So, after you do that, you have to download the parts to your project. And it's fairly easy to do that now because we have already done all the setup that we need, now we need to create a pod file like we did before and we're going to use that pod file in order to bring in the projects, the OneSignal into our projects. So, as you can we have a pod file over here and make sure you copy the latest version. So, I'm going to copy this one over here. So, it's kind of like 2.6.2-3 versions and make sure you copy the latest version that are shown in the documentation, okay? So, let me close this down and let me go to my project folder because I already have a pod file in my project folder. So, if you're doing this with a new project, you have to run pod in it and you know how this works. So, let me zoom in so we can see it better. So, as you can see I have this Firebase pods and I have this as the web image pods, so I'm going to bring in the pods as it is. So, we have to change something over here, but I'm just going to show you what will happen if we don't change it. So, it's actually a good idea to read what you're doing before you do it. So, I'm going to show you how this works. After copying and pasting and saving it in the pod file, I'm going to open my terminal because as you know, I'm going to move into my folder with change directory comments. So, my folder is under Downloads. So, if yours is like in the desktop you have to run CD desktop, and then you can find your InstaCloneFirebase folder. And then later on I'm going to run pod install, and it won't install these pods for me because I haven't configured it in a very proper way. As you can see, it says that you have a target named project name over here and it doesn't make sense. So, we have to change that and we have to change something else as well. So, let me come over to my pod file one more time so that we can try to change it. So, let me go over to my 'iOS Complete,' let me go over to my InstaCloneFirebase, to my pod file and open it, okay? So, let me zoom in so that we can see it better. And over here we're going to see something called project name, and we have to change this project name, yep, because we don't have this project name, we have InstaCloneFirebase. So, let me copy this and let me paste it over here. So, we have to change this target, and here we have this OneSignalNotificationServiceExtension as you can see. So, this won't resolve our issue I believe, because if we run pod install one more time, you will see we get the same problem because we need to do one more thing. So, targeting the app and targeting the one signal notification separately makes sense, but you have to just cut this pod and paste it over here because we already have this target over here, right? So, now I just say pod OneSignal and 2.6.2 3.0, and in the One Signal Notification Service, I have the same exact versions. Again, you have to use the latest version and the run pod install, and this time it will just install all the related dependencies for me. As you can see I have already Firebase and other ones in my computer, so it shows in black but I'm downloading the OneSignal as a new pod so it shows in green, and I believe it won't take much time because we already have Firebase and we're just downloading one single pod over here, as you can see it's already finished. Now, I'm ready to use One Signal, okay? So, let me close this down and let me open my workspace project, not the project file but workspace file. And after that, as you can see, we have to let me come over here, we already did that. We already imported this in our extension, and let me go to extension, and as you can see import One Signal doesn't give any error right now, it's already indexing so everything seems to be synchronizing and working in my project, so there is no any issue. So, let me go back to documentation one more time, and we did that and now we have to add the required capabilities inside of Xcode as well. So, here it is shown how to do that but it's actually changed in the iOS 13. So, if you're using XCode 11 and above, you will just have to follow my lead rather than this. So, let me come over here and show you how it's done. If you come over here to sign in and capabilities, you won't see any capabilities. So, in order to add one, you have to come over here and drag and drop something, okay? As you can see it's my target over here selected, so make sure your target project is selected rather than your extension, and if you cannot see a menu like this, let me show you how to find this. So, you have to come over here to capability section. And if you hit over here it will open something like a library, and you will see the push notifications over here and bring in that one and it doesn't end there. Unfortunately, we have to bring in one more thing and it's called background services, background modes. So, bring in the background modes and under background modes, you have to find this remote notifications, okay? So, make sure you select the remote notifications and make sure you bring in the push notifications as well. Finally, we have to add the required code. So, as you can see we have a required code in order to start this under didFinishLaunchingWithOptions  in the app delegate as usual. So, you have to just copy and paste this code, but this time you have to give your App ID as well, your OneSignal ID as well. So, let me come over here to App Delegate and paste everything here, okay? As you can see this is something like running firebase.configure, but it's actually a little bit longer. So, let me import the One Signal so that these errors will go away and we have to change only one single item over here which is our app, OneSignal app ID. So, we had this before. Remember, we had this given over here. So, you have to copy this App ID and come back to your Xcode project where you can just paste in the App ID over here. So, I know this is a lot and this is taking too long, but right now we are ready to use it. Right now we have brought in the certificates, we have done every setup that we want to do. The last thing that we want to do is to come over here and just import One Signal, we already done that. And as you can see it asks us to paste this in under AppDelegateDidFinishedLaunching WithOptions. We already done that and now we are done. Now, we are ready to send our first push notifications finally. Let's stop here, and within the next lecture we're going to see how to send our push notifications manually from the OneSignal dashboard.

 

About the Author
Students
1411
Courses
55
Learning Paths
3

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