 Hi, hello Hope everyone is alive Still live. Yeah, that's good Okay my name is Sohail and So here we are going to talk about the notifications By the way, who uses who all uses notification in the app? Few of them. Yeah, good Who uses remote notifications? Push notification are yeah, which is coming from the back end. All right. Yes from the back end not from the within that Yeah, notifications as we all know is one of the best tool for marketing By fact it is it Increases the engagement of the app by 80 percent 80 percent additional engagement And it is one of the very powerful tool for for keeping the users using the app like one of the study was found that People who have have activated the notifications. They open App at an average of 14 times in a month Compared to the people who do not have activated the notification. They open five times that particular app in a month So it is helpful very helpful now Well, there are two types of notification one which is within your app when something tasks happen and you push you send a notification the other one is the remote notification which is Which you push from your server, so Yes, let's see this how how that I mean in general the notifications Are not cross-platform. So every platform they have their own way of Their own implementation also like Google have their own cloud messaging service Apple has their own Apple push notification service and The way it works is that firstly you have to register the device ID So whenever the device comes up, they have to connect to the to the platform specific Service, let's say Google's if it is Android it has to connect to the Google's cloud messaging service and Register the device so that the Google's cloud messaging service will know that Divide this particular device has this IP address and then later when they want to push a notification they will They will know where to push it. So So the first step is that from the device You say you register to the notification service and get back the device ID And and save that device ID somewhere in your Backend and whenever you want to then later push the notification you send that ID to the push notification service And then it will send that to the to the device So this is how normally it works So in in in case of Google now they change the name so now the new console firebase So it's called firebit cloud messaging And then it will so from your back end We'll push it to generally the cloud message Firebase cloud messaging for Android and push it to Android and in case of iOS We'll push it to Apple push notification service and then it will forward it to the iOS device But to the problem in this is that you have to do it separately for each platform See your interface would be different for different platforms So if you have three platforms your interface would be three different interface and three different codes for doing that How we can simplify that is using Azure notification So your back end would only push to Azure notification You will set up But once you have set up the Azure notification Up with your firebit cloud messaging and Your back end has just push the notification to Azure and Azure will push it to the relevant whatever the platform it is The way it works is this way So the same thing the notification has been added here. So first you Register your device with a notification service and get back the device ID Somehow then send that device ID to store it in your back end and wherever you want to use You want to send a notification to that user device You send that device ID to the notification hub in a good forward way To its respective user or device So this is what we saw now Few scenarios when this can be helpful. I mean these are some of them, but not limited to One is maybe let's say location based service An example of this would be trip advisor So you why if you have trip advisor app install on your system and you would have seen if you are Near some famous location it gives you notification that Do you want do you want to look around the food? restaurants Around this if they say if I am I'm in Sentosa it will come up and say that They are great places around Sentosa. Do you want to take a look? So location based services promotion content If if you have food panda like me install on your on your Phone, which is one of my key app They they send push notification like 20% off or something like that So that you you keep on using their services. So promotion content send reminders If the something I meet up so if meet up Some of the events date or time has been changed at the last minute The location has been changed at the last moment the Meetup app gives you the notification send your notification multifact authentication Like telegram, which I know does that so whenever you go to desktop Web web telegram interface it sends you the code to the to actual mobile application of Telegram and from there you have to enter that code So these are fun few of the scenarios, but they can be limitless Scenarios where you can use the push notification But when to use Azure notification why to use Azure notification up for say this cross-platform so You don't need to create a different interface for each of the platform not just for Android and iOS and Windows. They also it also supports Kindle by do those those platforms as well So you have common interface no different No repeated code and device registration, so if you You still need to do some platform specific code because it is Notifications are not cross-platform. So you won't be able to use it from Xamarin forms But what you can do if you are using a Xamarin form you can simplify the registration process and use the dependency injection to just use Do the device registration from the from your form app But you will still need to do a little bit of platform specific code, but from the back end you will have a common interface Different delivery patterns so Azure notification have different delivery patterns So once you are registered with the users and their devices you can select either you want to send a message to a Either you want to send this push notification to a user and if that user has It's on multiple devices like for example my application I'm using it on Android and iOS both are signed up from from for same user user if I say on On Azure notification up if I say that I want to send it to user and if that user has three devices or four devices It will send to all of those devices So you don't need to do that logic in your app or in your back end all you can say you want to Send a notification to a specific device and then it will send it to a specific device You can schedule the notification. So right if you do not want to send a notification right now But you can send the notification in a scheduled way in Azure notification hub and Azure notification hub will schedule that Notification for you for in a future and then it will deliver to it. So there are different delivery patterns You can personalize the push so they are key pattern values which you can use to use the name of the users like Hey, so hell You are you have not ordered food from seven days. Are you are you a starving boy? So something like that. You can personalize it scalability again If if you if your app is really doing well, and you want to push notif you're push notifications like for example, if you're using for messaging or If your app has social components where there are a lot of messages coming for back and forth or posts comments likes So from from a single person from a single Just imagine and I mean what's that how many Notifications you receive per day in a what's that maybe like more than hundred notifications, right? so if you are a half has some kind of social component and One user is having hundred notifications per day on an average and if you have Maybe hundred thousand users that multiplies to easily 10 million Notifications on an average So if if you have to send those notifications from your back, and you will need to do the architectural changes To to make it to that scalable, but if you're using as your note of notification hub It is pretty easy to scale that level so those are the few reasons why why to use as your notification hub and I Think yeah, that's that's on the theory, but let's see how to do it actually So I'm going to straight away Go to the more Microsoft Azure portal and We'll first try what we need to first do is Let's see this one Okay Hmm So first we need to configure the Azure notification hub and then we need to configure the firebase and then your our Android app and then the Apple Notification service and then our iOS app. So this is what we'll do. So first Let's do the Azure part so on Azure you have to click new and In web.mobile, there would be somewhere down there. Yeah notification hub and I would give a notification hub name Notification monkey Yeah, and I would create a new namespace With the same name, yeah Locations out east Asia. Yeah, and I would use my existing resources or you can use you can create new resource group Pricing industry. So here you can see what I was saying about Free pricing tire. So this is the free pricing that even if you do not want to use The paid one you will still get one million pushes So one million Notification per month you can send in a free tire and even if you want 10 million It is just $10 per month. So it's not that expensive so I will select the free one and then create and In some time it should Create that. Okay. So deployment started and then it should say it is done. So while the deployment is Why it is creating that notification hub The next step is to create on Android I believe it is okay. It is still done. So for Android, you need to go to console firebase Google.com and Which is a new interface by the way And here you need to create a new project. This is for Android and We need to Keep the name. I would give the same name so notification Monkey And I will select Singapore and this would create a new project as well Let's come here and see it is still deploying Is the connection all right? Yeah, this connection is all right. That's right. Okay deployment succeeded. So that's good Let's see that Notification monkey, okay, so this name space is notification hub and Let's say that Okay, so it is created Okay, I will now click notification monkey is also there now here in project settings cloud messaging This is the stuff which we need. So there are two things server key and sender ID This are this we will be needed. So first thing I would do is to configure let's go back to Azure In Azure I would see Notification services and here are the platforms. So you see Apple Google Windows Windows phone, which was the earlier version Amazon and by the So let's do first the Google so we need to set up our Google Notification our Google app here and it needs API key. So This is the API key the server key which we needed. So you just need to copy that and Paste it and save Okay updated successfully So from Azure we have set up the push notification for our Google app Now sender sender's ID will be used in our application Android application. So let's go quickly and Create one sample you would close this solution and I will create new project and Xamarin forms app, okay, and I will name it as same notification monkey and Yeah, I will name it like that Desktop is easier to access And this will create a new project Xamarin forms project but since it is not Related Specifically to Xamarin forms. We are going to use The Android and iOS application in particular but it doesn't make any difference. You just have to do the one-time setup and then Okay, while it is setting up come back here and In access policies if you click on access policies There are two connection strings here for the notification hub one is The permission is only listen and the other one is listen manage and send listen is a permission which you would be using in your app Where you only need to listen to the cert notifications Listen manage and send would be used in your back end where you would be also sending the notification from So this would be used in our app now Let me Okay So the first thing first I'm going to do the Android version And the first thing we need to do is add two components one is Android Cloud messaging Android cloud messaging client, okay, that's good added and Another one is Azure messaging Okay, Azure messaging is there Okay, once they caught these two components are added. Let's go and Create one constant file this constant file can be in Xamarin forms app now because it would be used from both Android and iOS so let's add a new file Constant And I will need to define here three strings I have it here already so we don't waste time on that and If you see here, there are three things sender ID Connection string and notification hub name Sender ID will be used for Android so on fire base Yeah, here fire base. We have sender ID need to copy that paste it here Listen connection string which we get from Azure this one will copy that Listen connection string and notification hub name is the name of the notification of which we have here Which is notification monkey. So I just need to paste that notification Monkey, okay Once this done this constant will be used when we add the notifications Coming back to Android application. We need to add two files here Let me fast from this process I will explain you this But let's do it. This is my project at files and Azure push notification browser Sorry broadcast receiver and service so broadcast receiver is Would be able to You will need to add we will need to add some permissions to for for notification to work and then this broadcast receiver Will initiate the service the push and the service push and the service is the one which will be using so, okay Not really this one, okay, I was referring to the wrong project. So maybe okay That's not a problem to change the name Notification monkey Okay, so some few permissions and then The service the name of the service a push handler service push handler service same thing over here, I'll explain it to you but You don't want to keep on writing this code here. So Let me just paste it okay What are this is a service which would be running in the guy has to be a service. So that's why we have service tag here Because we want to receive this the notification even if the app is not running and then and there are few and this is The service is Inherited from GCM service base Google cloud messaging service base And Google cloud messaging service base has few methods which we need to override So on registered will be called when we registered when the when the first step is done. So as a PTV so when When this step is done the first step where you are going to send Register the device and getting the device registration when that is done This event is going to be fired on. I mean the the method is going to be called and then What are we going to do is We will register the it on the hub using the Azure messaging Azure messaging component which we had that the library and then Done on the message is the on message on message is when the whenever we get the new push notification This message will be called this method will be called We will extract the actual message from here and just say create notification and create notification is going to create actual notification For the device and then we'll just and these are the few methods But we are not doing anything here on that particular thing So by this it should be it should Create a notification and push it. So let's try to test it And by the way, I will be using the actual device to test it because simulators are not a good idea to test the notifications So my device is here Let's say it's building So let's okay since this is building. Let's go back and see what we do. So This was for the Android the same way we'll need to be doing for iOS iOS is a bit Confusing how many have you gone through the pain of installing the provision devices? Yeah It is it is confusing I mean yes I say like So for Apple you need to first create a certificate for the push notification and then install that certificate Only then you will be able to add it and now let me check Okay, looks like Okay, so my app is running here Now let's see Let's try to send some push notification from here Ideally we would have one back end and then from that back end we would send a message Sender call the Azure notification API to send a push notification But here we are doing the test so here on the notification hub you have sent test and Can select the platform so I will select Android and it will send the message to Notification to all the Android which are registered on it. So let me say send So successfully send But I don't see it here. You've connected to internet Okay, I will come back to that later, but let's see the iOS one first So in iOS like I said it you need to create first a certificate now a little bit on certificate It's always very confusing So let me give you some Backdown on on the certificates What actually I can do is Let me go here Encryption on What's up what's okay Hopefully Yeah, yes my Yes me, okay So Generally, I mean If you guys are not familiar with the certificate what happens in certificate is that there are always two set of keys One is the public key and one is private key now the key is a mathematical to very large Prime numbers, you know and those two prime numbers are Usually in a way related that if you if you do some calculation like for example If you multiply by if you do that calculation with the with one prime number And do the same calculation with another prime number. You will get back the original result so There is this relation between these two primary and very large prime numbers so If you have one prime number There's absolutely no other no way that you can trust the another prime number So in a easy terms, they are always two keys one is a public key one is a private key If you encrypt anything with public key You can only decrypt it using the private key and if you encrypt something with a private key You can only decrypt it using the public key So in encryption how it works is that The private key you always use you generate Two keys public key and private key are always generated in a pair and private key you keep private so you do not Share that private key with anyone public keys for everyone to share now if let's say I have I Want to send something to Someone what I would do is I would encrypt my I would encrypt that message with my private key And then there would be some message which would be generated that message can be No, sorry Confused This is how it goes, okay, so let's say for example if I Know Bob wants Bob want to send a message to Alice, okay Now Bob has its own private and public keys and Alice have his own public and private key now If I want to send a message to To you for example, I will use your public key because public key is public right It can be it can be available for anyone to look at it So I will use your public key and encrypt that message with your public key But nobody else would be able to decrypt it because The only key which can unlock that message is your private key and the private key is with you only So we describe it so nobody would be able to read that message And when you introduce when you receive it you unlock it with your private key and the message is that the same Happens with the other way when you want to send me the message you will you would encrypt it using my My public key and then when it comes to me, I would Unlock it or and decrypt it using my private key and then I would have it This is how the encryption work, but we are not using encryption here We are using code signing so signatures are absolute are Exactly opposite of encryption in encryption you always Encrypted using public key and decrypted using private key, but in signature You encrypt using private key and decrypted using public key. It's a little bit confusing But why would you do that? Let's say for example? I Want to say that this is something which I authorize or This is something authentic coming from me What I would do is I would dig I would encrypt it using my private key and Push it to forward now anyone who has my public key can decrypt it and see the content That's fine. That is not the purpose. The purpose is that Nobody would be able to decrypt Encrypted for my private because it's only me who has my private key. So Only one person it is it would be truly authenticated that this information is signed by me only and not by anyone else so in terms of application when we submit the Applicator the Apple code it always signs even if it is Android or Apple It does science with the care pad of that public with the private key Why does that nobody know all other developers can sign your code and publish it on the server so in that way your code is protected and That's so that's the concept of public key and private key. So to clean it to be generated now Always the private keys and the public key when they are generated it has to be generated on your machine If it is generated on the server and then you transfer it through a network It is going to be compromised. It's risk to be compromised So it is always better to generate it on on your machine now one way to generate it on the Mac is using kitchen access Go to kitchen access services No certificate assistant. Yeah, thank you and request certificate from certificate authority and I would enter my email address and I will say save it to the desk now This will create Yeah, yeah, this is a request. This is this will generate the two keys, but it is not yet The certificate is not yet signed by Apple so we will submit it to the apple to sign it back But before that we'll create a request. So this is creating a request. I already have one request here So let me just delete it Okay good The request has been created now Now coming back to Apple Okay, so first what we need to do is Create a new Apple ID. Okay Create a new app ID. So go to the app ID Add new app ID the name I will say same note notification Monkey and Bundle ID which remember I had there calm dot Alza, which is my company name and then Notification Monkey It's very important to have the same bundle ID as you have in the project. Otherwise it won't work And Then here we need to select push notification and continue it gives you the Confirmation notification monkey identification Everything looks good. Okay. I will say registered Done Notification monkey is registered. Okay. The next thing I would go and create a certificate. So on certificate plus Certificate is Apple push notification service certificate and then Let's say continue I'll select my app ID, which is notification monkey and continue and Then continue and then I would upload the CSR the certificate request, which I have created earlier Which we created earlier and saved it on desktop I will select that open and continue Okay, so the certificate is ready download it and say done Now I need to add this and This will be added in my if I double click on on Mac. I will add it To my certificates Should be here. Yeah notification monkey and here's the key So it's a private key with the public key certificate. Okay. That's great One last thing which we need to do is Let me just create a provision profile I'll just say And this is iOS app development provisions of profile. It's not a notification Profile and I would select notification monkey Continue I'll select one of the certificate and My iPhone and Same name here notification monkey profile, okay And continue or download that as well and done. Okay Should be added Now we need to move to okay one more thing when we have added here in the kitchen this Certificate of notification monkey which we created this is a certificate which we need to upload it to the Azure notification Enable to configure to the push notification. So what I will do is here is export and I'll name it something and this is the extension which you need to select P 12 The difference between the CR and P 12 is that the CR only includes public key So if you want to give it to someone else who want to encrypt the message And send it to you. You just select here, but this one includes the public key and the private key So never give some hurry or P 12 to anyone. It includes your private key as well So save it you need to give the password because it also keeps the private keys So and this is just a passphrase which protects your private key So you need to enter this password to open that file I would just give a simple password here for now and say, okay Hello, and this is the P 12 file which we have here. So this we need to add it To Azure So coming back to Azure Of course, if you I mean, yeah, you you give up on Microsoft. Anyways, you are using Visual Studio Visual Studio team services everything so Yeah, of course exactly Again coming back to notification services Apple Here we need to upload the certificate P2L file The password any password to open the file, of course So I would give the password which I created that I will I'm selecting sandbox because we are not doing the live here Okay, so the certificate thumbnail has been printed here This looks like our App our application Apple and Google have been configured for the notification services Notification set up was like instant. It's like a figure. Yeah You can just like snap your finger for long time. Yeah, exactly. Exactly. Yeah But it's It's always I mean it's a pros and cons I mean the Google is just using the app key So anybody has your app key can literally send the notifications But in in terms of Apple, it's a public and private key of your complete P2L package And even if they have the P2L package, they need the Password to open that file. So yeah, that's why Never conclude too easily So coming back here on iOS so on iOS, let me change this Here again, we need to add a package or the component The same component as your messaging Okay, and if you add the measure as your messaging it shows your documentation that you need to add this few code In your app delegate file when finished launching and then Registered for remote notification and received in notification. So this tree matter you need to add so I will do the same thing Again to save the time I would copy from here Let me just copy this what I would do is before I launch my Xamarin forms event. I would Okay, we need to add here Okay, ah Sorry, let me see This is the one for from Azure notification Up and there are two. I mean there are different ways They keep on changing the API. So before Version 8.0. There was different type of registering for notification after 8.0. It is different API and now even on the After 10.0 iOS 10 is another API, which is a new API. I haven't added it. This still works But there's a new API for that as well Again the same thing We need to add this two functions and others are just placeholders Okay So receive notification again when When there will be new notification this method will be called and we'll call the process notification with some data Which is received and will extract. So this method is extracting that Data. So if you go here Where is my Azure? Yeah, Azure coming back to test send test and if I select Apple So it's a JSON which will be sent so APS and then inside that alert and then what if it your message Whatever message you had and this is when you can configure however you want, but this is default So basically what we are doing here is the same thing we are extracting those keys key value key and and inside that we are Extracting the message and then one more thing which we are doing here is that if if the app is Running in if the app app is on front if it is Not in background it is in front then the notification will not be sent will not Be triggered the platform will not trigger the notification push notification because the app is in foreground If that is the case we need to somehow Still I mean I mean notify the user that there was some notification in in terms of any app notification maybe we do it So for now here, we will just display the alert view and The other apps other are just a function which we are not doing anything here. I'll just go the function from the Delegate app delegate now Doing this I Think yeah, it should be enough. It should work now. So let's try this Again the same thing don't use the simulators. So I would use my device here and Let me just Okay, so just if I have my device here and Let me Build it's building Okay, good and running the questions by the way Yeah Yeah, we have taken take care of that you still have to do that so when you are registering So let me go back Here in app delegate we have No, we have installed the provision profile already Remember when we downloaded a provision profile and set up it up, but here you just need to take care is that Yeah, here you are not here. This is not visual studio So here you just need to take care of the bundle ID, which you need to make sure that this is the same bundle ID Yes, yes, of course Which will get it in that moment the second There's there's a lot of statistic on the issue so you'll ask me for the permission first allow Oh Okay, let's let's try to push notification from here the sand should walk Apple and sand Yeah That's not good. Hmm. Okay for this reason I have already pre-configured app, which is this You know if this happens right Only this room only this room Let me try this one. So this is the exactly same one. This is the app, which I was copying the code from Here Let's try from this one The last time I I know this was working, but let's try again. It's what's on my machine my way Ah, okay So So this this we already Handled the in-app notifications because the app is in foreground. So when we go in background we send it again and Should appear there. Yeah But you can also use the tags. We have not used the tags We are just sending but you can use we can use the tags to identify what kind of Of what kind of context you are sending those notifications to and then depending on that you can Customize your experience And there are a lot of different Other tools which you can use here When we selected the the the tier the free tier that doesn't have that but If you select the standard one You get the rich telemetry of all the analytics and there's a lot of things which you can do from there You can schedule the push in the in in later state Multi-tenancy. Yeah And and just look at the price difference is from $10 to direct $200 So, yeah Is going to be connected with the community services Yeah Microsoft is new google Yeah, so that's that's um, that's how we can use the notification On the azure My phone Windows Yeah I cannot demonstrate the windows here because I'm using the mac And I don't I don't use the But yeah, it's a same concept you need to do the registration and then Connect it to the azure and then send it. So the same thing. Yeah Any questions We need to go to the bar And Okay, cool, then I said Yeah