Implement Push Notification In .NET MAUI Part-2 (iOS)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome to my channel in this video I am going to demo about implementing post notification .net mavi for the iOS platform so I already created one video on implementing boost notification for Android platform so same project I am going to use here for iOS platform also and we noticed that like in Android when the notification was received and when we click on notification that time application was crashing so I found the solution for it so let's implement the solution first so here in a Firebase Service First you need to set this intent so when the when we send the notification that time we are creating intent here so clear in 10 just add Flags single top so it's going to receive notification on the same activity instead of creating new activity okay now let me run the application so when now when the user click on notification that time application is not going to crash okay so here notification receives now when I click on notification our application is not crashing but it's creating new intent it's not creating new activity so this code is now not going to work like whatever the navigation ID that we received from notification we saved in preferences so this good now I need to add here in on new in pen so when the new intent was created so that time this intent contained notification related data so now when I click on notification it's just going to save data in preferences okay so now when I tap on notification it is going to invoke this on new intent and data stored in preferences okay now to communicate like from Android platform page main activity uh to here on main page so I need to use messaging center so that messaging center was deprecated in.net mavi so I need to use weak reference in messenger so for that let me install Community toolkit.mvbm plugin in this project so this plugin I'm just going to install in our push notification project okay and here in models I am just going to add another model called push multi boost notification basic model and here I will use value change message and that our message will be in string format okay now let me register this push notification received class uh with a weak reference messenger here on Main page.jam.cs so yeah I'm just going to use weak reference messenger dot default dot register in that I'm just going to specify this post notification receive class okay so here it's just going to receive the message in a string format okay so this message dot value going to uh received in string format because we defined here value chain message as a type of string so that just going to resume in string format now let me just send this week Corrections messenger from Main activity so here when the notification is received then I am just going to call the pnb reference messenger dot strand in that I will just pass this post notification receive class with the parameter like whatever the value you want you can pass even you can pass this notification but I saved in preferences because like when the application closed and again we go reopen the application then from the preferences it's just going to navigate foreign okay now let me run the application so here uh when this week reference messenger uh involved that time it's just going to call this method and from the preferences we're just going to navigate to particular page and if the application is closed and data stored in preferences so when the user open the application that time also is just going to navigate to paste based on the navigation ID okay PL notification received and when I tap here so it's navigated to another page okay so this Android issue was uh fixed now let's Implement boost notification for the iOS okay so for the iOS platform first win to create Apple development certificate bundle identifier then the provisional profile and APN key for the push notification in apple developer account so let me just show you so here I just created one blog related to this I will add this link in video description so first you need to create a development certificate in your Apple developer account so if you have a apple developer account then you will see this option certificate identifier devices and profiles so this all option you will able to see that so just create a development certificate and then download it and install in your Mac system after that you need to create a bundle identifier of your application so just add bundle identifier of your application with the what is the application ID you are using in your project so just click on your project and click on properties so here in Marvis add option you will see this application ID so this application ID used as a package name in Android and bundle identifier in iOS so with the same application ID you need to create a bundle identifier here in apple developer account after that just add your real device in devices section because for testing push notification you cannot paste that in simulator so you need real device so just add that device ID here in devices section after that you just create a provisional profile development or distribution provisional profile here in profile section with this bundle identifier option so after that just download it and install in your Mac system okay so once the profile is created after that just add APN key in a keys option so that key will be used for post notification and you need to save that in some safe place because you can only download it once after that you cannot download it again okay so once all the certificate creation is done now you can add uh you can create your project in fire which console so here in a Firebase console just create your project and if you have uh already created project just click on existing project after that just click on add app section and see here select iOS option so here just need to add application ID that we just seen so that application ID just add it and then just click on register offset and after that just download the config file so I already created it okay so after downloading Google service info dot PLS file you need to do another configuration is adding APN authentication key here in a newly created iOS application so for that just click on Project setting option and then select Cloud messaging tab and there you just need to upload that APN authentication key that you created in apple developer account after that here you need to add key ID and the team ID so key ID you will get from a key section like the key that you created in apple developer account so that just click on that key uh there you will see the key ID of your APN authentication key and for the team ID so you will get that from the membership detail page of Apple app developer account from there you will find the team ID so just add that APN authentication key with this all detail and just upload it so once it uploaded then that certificate related stuff and this Cloud messaging related stuff is done now we can Implement that in our project so let's do that okay so now let me add that Google service info dot PLS file in iOS platform so here in iOS folder I am just going to add that googleservice.info.pilis file and here in a zombie in when you click here on properties then you will see here build action as a bundle resource but that option is not available in dot net value so for that here we manually need to modify in this project file so just right click on your project and click on edit project file and here you need to add item group with that so let me add here so the way it did for Android it's the same way we need to do for iOS so here I'm just going to add another item group that just uh going to point iOS platform and here instead of Google service Json we need to use bundle resource and here I will just provide that Google service input.please part also same part here I am just going to specify here in link option okay so this project is already connected with my system so here in a project properties I'm just going to select iOS bundle signing option to manual provisioning and here I will just select my Apple developer account and it automatically going to identify my provisional profile if it is installed on my Mac system so it's already installed now here I am this going to select iOS Remote device and I will just select my device here and now let me just try to run this application okay so it's deploying on my iOS device so here in a any Dax I'm just going to this QuickTime Player to mirror my iOS device okay so this application was installed here but it's not launched so let me again try to run okay so now it's run sometime it so error like this just you need to rebuild so now that our that code we added bundle resource in a project file that's working now let's uh add push notification related code uh code for iOS platform okay so first here in a dependency of dot Net 7 iOS I'm just going to click on here in manage muted packages and I'm just going to install Firebase Cloud messaging plugin so just search for firebird.cloud messaging and just install that in your project okay now once you install this plugin here in the app delegate.cs file I'm just going to write finish launching matter and in that I am just going to configure Firebase so like if you add any other Firebase service which like Cloud messaging or Firebase analytic so it just going to configure based on this file that Google service info dot please file we added so after that we can use any Google service for iOS platform now let me request for the permission for the Post notification in iOS so for that here I am just going to check UI device that current device check system version is greater than 10 so if it is Android iOS 10 and above version then here I am just going to request full so enter Dash alert or sound with this option I am just going to request for the permission so the quiz authorization and with that I will pass this part options that we we are specified and now like once the weakness is granted or is there any error occurred So based on that you can just display some message so if it is true means that that permission is granted for the Post notification if it is false then you can like display some message now for generating device token so here messaging dot set instance dot photo initial I am just going to set to true and here messaging dot settings dot delegate so I need to set iMessaging delegate here so for that here I am just going to use iMessaging delegate interface here I am just going to add and that now I can set here so it is going to set I'm asking delegate to this messaging dot side instance dot delegate now I can just register for remote notification okay here in a iMessaging delegate this did receive registration token method exist so when user install the application so that time it just going to receive the registration token so let's export uh this date review registration to connect third here in app delegate so here I am just going to create one method did received as assistant open uh with this two parameter one is a messaging type object and another is just string format registration token yeah I am just going to export this selector method so this selector I am just going to specify here so when the user install the application that time based on selector this method is going to invoke now this registration token I am just going to add in preferences the way I did for Android so here in Firebase service let me copy this code and this code I'm just going to add here okay now I am just going to create a user notification delegate so when the notification is received then we can handle the navigation like which page we want to navigate so for that here let me create one class in iOS I'm just going to create user notification center delegate class and this class we're going to extend event user notification center delegate and here I am listening to override will present notification so when the application open and notification received and it is going to just display the notification okay and another method I am just going to override is did resume notification response so when the notification is received and this method is going to involved now this user notification center delegate I am just going to set here in app delegate this newly created class I'm just going to add here okay now here in input.please file I'm just going to set new notification permission so here in a background mode I am just going to set remote notification and background Edge to true okay so here application installed and asking for to allow push notification permission as well as here uh registration token also received that this token I am just going to copy and let me just continue and allow permission okay now I'm just going to try to send notification using Postman so before that let me put debug Point here in this user notification center delegate so first I am just going to put debug here in will present notification so let me open Postman and try to sign notification here I'm just going to add this token and let's see okay so now this method in work will present notification and here in a Mac notification visit but here screen mirroring is running due to that it's not showing but if I pull down then you will see this notification received here now let's handle like if the user tapped on notification then this method will invoke the resume notification response so from the response I am now going to navigate to particular page uh based on the condition the way we did for Android so let's add a code related to that okay so from this notification response I'm just going to fetch uh what are the information sent from this notification data so let's add so from the response dot notification dot request dot contain and from the content I'm just going to fetch user info okay so from this user info request and that going to contain navigation IDE so that idea I'm just going to fetch here and let me set that in preferences okay so same way I'm just going to do the way I did for Android so I'm just going to set this Interruption since and after that I'm just going to call this week reference messenger so this navigates an idea I set in preferences after that I will transform this week reference messenger dot send okay now let me run the application and let's see on the tap of notification it's navigating to other page or not okay so here application launch now from the postman I'm just going to send the notification okay and from this notification I am just going to tap so it's navigated to new page okay and another thing I want to say that whose notification that uh we are sending that we are using Legacy version to send the post notification here on Postman app cm.google.com so now the new way is to send notification is we need to use uh this fcm Google apis.com then we need to mention your project ID then send and then we need to generate a barrier token using Firebase admin SDK okay so you can just take a look at this document to how you can use a new way to send the notification and I will also create a new video on like how you can use Firebase admin SDK to send notification so in next video I will just show you you can use that Firebase admin SDK on a web also and the mobile also and with that you can easily send the notification foreign if I click here on click me button also now it's just going to send the notification and if I see here so the notification is received and on the top of that it navigated okay so that's all for today I hope you like this video and thank you so much for watching it
Info
Channel: Programming With Pragnesh
Views: 5,776
Rating: undefined out of 5
Keywords: Push Notification In .NET MAUI, Implement Push Notification In .NET MAUI, .net maui, .NET MAUI, Push Notifcation, net maui, maui c#, maui tutorial, maui .net, maui, C# maui, dotnet maui tutorial, blazor tutorial, blazor crud, .net maui app, Implement Push Notification in iOS, iOS Push Notification
Id: YNkdsJTyOJE
Channel Id: undefined
Length: 29min 15sec (1755 seconds)
Published: Sat Mar 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.