%3CLINGO-SUB%20id%3D%22lingo-sub-1130629%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Azure%20Notification%20Hubs%20in%20Apache%20Cordova%20and%20Ionic%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1130629%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20to%20integrate%20azure%20push%20notification%20into%20our%20ionic%204%20app.%20We%20don%E2%80%99t%20use%20capacitor%2C%20but%20just%20cordova%20only.%20Any%20tip%20on%20how%20to%20do%20it%20or%20where%20should%20we%20start%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1131003%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Azure%20Notification%20Hubs%20in%20Apache%20Cordova%20and%20Ionic%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1131003%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F533541%22%20target%3D%22_blank%22%3E%40MingLeung%3C%2FA%3E%26nbsp%3Bno%2C%20I'm%20sorry%20but%20I%20didn't%20do%20any%20testing%20with%20Ionic%204%20and%20Cordova.%20I%20assume%20it%20works%20the%20same%20as%20Ionic%203%2C%20but%20I%20didn't%20do%20any%20research%20there.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1173367%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Azure%20Notification%20Hubs%20in%20Apache%20Cordova%20and%20Ionic%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1173367%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F332916%22%20target%3D%22_blank%22%3E%40johnwargo_ms%3C%2FA%3EThanks%20for%20the%20wonderful%20article.%3CBR%20%2F%3EI%20have%20followed%20this%20entire%20article%20and%20I%20am%20able%20to%20send%20and%20receive%20notifications%20in%20my%20ionic%20app.%20I%20have%20used%20capacitor's%20Push%20plugin%20and%20event%20listener%20for%20registration%2C%20grabed%20the%20device's%20push%20token%20and%20sent%20it%20to%20my%20app's%20backend%20for%20Azure%20Notification%20Hubs%20registration.%20I%20am%20able%20to%20receive%20these%20notification%20in%20my%20app%20through%20alert%2C%20but%20these%20notifications%20don't%20appear%20on%20my%20android's%20notification%20bar.%20Do%20I%20need%20to%20add%20anything%20extra%20for%20that%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1179483%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Azure%20Notification%20Hubs%20in%20Apache%20Cordova%20and%20Ionic%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1179483%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F557344%22%20target%3D%22_blank%22%3E%40divyasmehta%3C%2FA%3E%26nbsp%3BI%20think%20that%20depends%20on%20the%20type%20of%20notification%20you%20send%20to%20the%20device.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1056685%22%20slang%3D%22en-US%22%3EUsing%20Azure%20Notification%20Hubs%20in%20Apache%20Cordova%20and%20Ionic%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1056685%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Notification%20Hubs.jpg%22%20style%3D%22width%3A%20226px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F180176iC4C1F99EE458F005%2Fimage-dimensions%2F226x118%3Fv%3D1.0%22%20width%3D%22226%22%20height%3D%22118%22%20title%3D%22Notification%20Hubs.jpg%22%20alt%3D%22Notification%20Hubs.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMany%20of%20our%20customers%20use%20Apache%20Cordova%20or%20the%20Ionic%20Framework%20for%20their%20mobile%20apps%20as%20a%20way%20to%20deliver%20cross-platform%20mobile%20apps%20to%20their%20customers%20and%20employees.%20While%20Azure%20Notification%20Hubs%20doesn%E2%80%99t%20directly%20support%20these%20frameworks%2C%20Ionic%20supports%20most%20Apache%20Cordova%20plugins%20and%20there%E2%80%99s%20an%20official%20PhoneGap%20Push%20plugin%20you%20can%20use%20as%20well%20as%20a%20community-built%20plugin%20for%20Azure%20Notification%20Hubs%20apps%20running%20on%20Apache%20Cordova.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20PhoneGap%20Push%20plugin%20doesn%E2%80%99t%20support%20Azure%20Notification%20Hubs%20directly%2C%20but%20you%20can%20use%20it%20for%20the%20device-side%20part%20of%20the%20device%20registration%20process%2C%20using%20your%20app%20backend%20for%20the%20rest.%20I%E2%80%99ll%20describe%20that%20option%20later%20in%20this%20post.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20community%20plugin%20for%20Azure%20Notification%20Hubs%20is%20not%20supported%20by%20the%20Azure%20Notification%20Hubs%20team%2C%20but%20many%20of%20our%20customers%20use%20it%20for%20their%20production%20apps%20today.%20For%20Apache%20Cordova%20developers%2C%20the%20instructions%20included%20in%20the%20plugin%E2%80%99s%20readme%20show%20how%20to%20use%20the%20plugin%20in%20your%20apps.%20For%20Ionic%20developers%2C%20later%20in%20the%20post%20I%E2%80%99ll%20highlight%20sample%20applications%20for%20Ionic%203%20and%20Ionic%204%20I%20built%20using%20the%20plugin%20so%20you%20can%20see%20how%20to%20use%20it%20for%20your%20Ionic%20apps.%20These%20samples%20are%20just%20that%3A%20samples%2C%20provided%20to%20show%20you%20how%20I%20did%20it%20while%20recognizing%20that%20they%20might%20not%20work%20today%20based%20on%20changes%20in%20the%20Ionic%20framework%20and%20the%20underlying%20Apache%20Cordova%20(for%20Ionic%203%20apps%20and%20Ionic%204%20apps%20built%20on%20top%20of%20Apache%20Cordova)%20or%20Capacitor%20(Ionic%204%20apps)%20runtime.%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId-356658225%22%20id%3D%22toc-hId-356658225%22%3E%3CFONT%20size%3D%225%22%3EUsing%20the%20PhoneGap%20Push%20Plugin%20in%20an%20Apache%20Cordova%20App%3C%2FFONT%3E%3C%2FH1%3E%0A%3CP%3EThe%20%3CA%20href%3D%22https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fphonegap-plugin-push%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPhoneGap%20Push%3C%2FA%3E%20plugin%20handles%20the%20process%20of%20obtaining%20a%20device%E2%80%99s%20push%20token%20from%20the%20device%20manufacture%E2%80%99s%20Push%20Notification%20Service%20(PNS).%20After%20following%20the%20instructions%20for%20adding%20the%20plugin%20to%20your%20Apache%20Cordova%20project%2C%20your%20app%20will%20have%20a%20call%20to%20initialize%20the%20plugin%20using%20code%20similar%20to%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Econst%20push%20%3D%20PushNotification.init(%7B%0A%20%20android%3A%20%7B%7D%2C%0A%20%20ios%3A%20%7B%0A%20%20%20%20alert%3A%20'true'%2C%0A%20%20%20%20badge%3A%20true%2C%0A%20%20%20%20sound%3A%20'false'%0A%20%20%7D%2C%0A%20%20windows%3A%20%7B%7D%0A%7D)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENext%2C%20you%E2%80%99ll%20add%20a%20registration%20event%20listener%20like%20the%20one%20shown%20below%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Epush.on('registration'%2C%20data%20%3D%26gt%3B%20%7B%0A%20%20console.log(data.registrationId)%3B%0A%20%20var%20deviceToken%20%3D%20data.registrationId%3B%0A%20%20console.log(data.registrationType)%3B%0A%7D)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20that%20in%20place%2C%20the%20value%20in%20the%20deviceToken%20variable%20is%20the%20unique%20push%20token%20for%20this%20device%20you%E2%80%99ll%20need%20to%20send%20notifications%20to%20the%20device%20using%20Azure%20Notification%20Hubs.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESend%20that%20device%20push%20token%20to%20your%20app%20backend%20then%20use%20the%20Azure%20Notification%20Hubs%20Installations%20API%20to%20register%20the%20device%20for%20notifications.%20You%20can%20find%20instructions%20on%20registering%20devices%20in%20Azure%20Notification%20Hubs%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fnotification-hubs%2Fnotification-hubs-push-notification-registration-management%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ERegistration%20Management%3C%2FA%3E%20documentation.%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId--1450796238%22%20id%3D%22toc-hId--1450796238%22%3E%3CFONT%20size%3D%225%22%3EConfiguring%20Azure%20Notification%20Hubs%20in%20Ionic%203%20Apps%3C%2FFONT%3E%3C%2FH1%3E%0A%3CP%3EIonic%203%20apps%20are%20built%20on%20top%20of%20Apache%20Cordova%2C%20and%20the%20Ionic%20team%20did%20an%20excellent%20job%20of%20enabling%20Cordova%20plugin%20support%20in%20Ionic%203%20apps.%20To%20build%20an%20Ionic%203%20app%20that%20works%20with%20Azure%20Notification%20Hubs%2C%20simply%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ECreate%20a%20new%20Ionic%20project%20following%20the%20instructions%20at%20%3CA%20href%3D%22https%3A%2F%2Fionicframework.com%2Fdocs%2Fv3%2Fintro%2Finstallation%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fionicframework.com%2Fdocs%2Fv3%2Fintro%2Finstallation%2F%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3EAdd%20the%20third-party%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fderek82511%2Fcordova-azure-notification-hubs%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ecordova-azure-notification-hubs%3C%2FA%3E%20plugin%20to%20the%20project%20following%20the%20instructions%20at%20%3CA%20href%3D%22https%3A%2F%2Fionicframework.com%2Fdocs%2Fcli%2Fcommands%2Fcordova-plugin%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fionicframework.com%2Fdocs%2Fcli%2Fcommands%2Fcordova-plugin%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EWith%20the%20plugin%20in%20place%2C%20initialize%20the%20plugin%20and%20respond%20to%20notification%20events%20as%20documented%20in%20the%20plugin%E2%80%99s%20documentation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20created%20a%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-notificationhubs-samples%2Ftree%2Fmaster%2FIonic%2Fionic-3%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esample%20application%3C%2FA%3E%20demonstrating%20how%20to%20use%20the%20plugin%20in%20an%20Ionic%203%20app.%20The%20sample%20implements%20an%20Ionic%20Provider%20for%20Azure%20Notification%20Hubs%20that%20manages%20registration%20and%20processing%20of%20notifications%20as%20they%20come%20in.%20When%20the%20provider%20has%20important%20information%20(like%20registration%20success%20or%20a%20notification%20message)%20it%20sends%20it%20to%20the%20application%E2%80%99s%20main%20form%20as%20an%20event%20notification%20which%20causes%20the%20app%20to%20update%20its%20UI.%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId-1036716595%22%20id%3D%22toc-hId-1036716595%22%3E%3CFONT%20size%3D%225%22%3EConfiguring%20Azure%20Notification%20Hubs%20Ionic%204%20Apps%3C%2FFONT%3E%3C%2FH1%3E%0A%3CP%3EIonic%204%20delivered%20big%20changes%20for%20Ionic.%20The%20Ionic%20team%20made%20a%20lot%20of%20changes%20to%20the%20framework%20plus%20released%20Capacitor%2C%20their%20alternative%20for%20Apache%20Cordova.%20Capacitor%20still%20supports%20Apache%20Cordova%2C%20but%20only%20a%20subset%20of%20the%20existing%20plugins.%20Ionic%20also%20built%20many%20common%20plugins%20into%20Capacitor%2C%20so%20you%20no%20longer%20%E2%80%98need%E2%80%99%20Cordova%20plugins%20to%20deliver%20certain%20functionality%20to%20your%20app.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20example%20of%20this%20is%20the%20Capacitor%20%3CA%20href%3D%22https%3A%2F%2Fcapacitor.ionicframework.com%2Fdocs%2Fapis%2Fpush-notifications%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPush%20Notifications%20plugin%3C%2FA%3E%20which%20adds%20support%20for%20registering%20for%20and%20processing%20push%20notifications%20to%20Capacitor.%20If%20you%20follow%20the%20procedure%20to%20create%20an%20Ionic%204%20project%2C%20add%20the%20cordova-azure-notification-hubs%20plugin%20to%20it%2C%20and%20add%20the%20code%20that%20registers%20for%20and%20processes%20notifications%20like%20you%20did%20for%20Ionic%203%20applications%2C%20you%E2%80%99ll%20find%20that%20your%20application%20registers%20successfully%2C%20but%20never%20%E2%80%98receives%E2%80%99%20any%20notifications.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat%E2%80%99s%20happening%20is%20that%20the%20cordova-azure-notification-hubs%20plugin%20is%20properly%20managing%20the%20registration%20process%20with%20Azure%20Notification%20Hubs%2C%20but%20the%20Capacitor%20Push%20Notifications%20plugin%20intercepts%20all%20notifications%20that%20arrive%20on%20the%20device%2C%20circumventing%20the%20Azure%20Notification%20Hubs%20SDK.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20means%20that%20to%20automatically%20register%20for%20and%20receive%20notifications%2C%20your%20Ionic%204%20application%20must%20use%20both%20plugins.%20The%20cordova-azure-notification-hubs%20plugin%20to%20manage%20automatic%20registration%2C%20and%20the%20Capacitor%20Push%20Notifications%20plugin%20to%20process%20them%20when%20they%20arrive.%20Special%20thanks%20to%20Matthew%20Podwysocki%20(Microsoft)%20and%20Mike%20Hartington%20(Ionic)%20for%20figuring%20this%20one%20out.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20created%20a%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-notificationhubs-samples%2Ftree%2Fmaster%2FIonic%2Fionic-4%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esample%20application%3C%2FA%3E%20that%20shows%20how%20to%20use%20the%20plugin%20in%20an%20Ionic%204%20app.%20The%20sample%20implements%20the%20same%20Ionic%20Provider%20for%20Azure%20Notification%20Hubs%20that%20manages%20registration%2C%20but%20adds%20additional%20code%20to%20use%20the%20Capacitor%20Push%20Notifications%20plugin%20to%20process%20received%20notifications.%20With%20that%20in%20place%2C%20it%E2%80%99s%20basically%20the%20same%20UI%20and%20logic%20as%20the%20Ionic%203%20sample%20(updated%20for%20changes%20in%20Ionic%204).%3C%2FP%3E%0A%3CP%3EThe%20Capacitor%20Push%20plugin%20also%20supports%20a%20similar%20registration%20event%20listener%20you%20can%20use%20to%20grab%20the%20device%20push%20token%20and%20send%20it%20to%20your%20app%20backend%20for%20Azure%20Notification%20Hubs%20registration.%20Doing%20this%20eliminates%20the%20need%20to%20use%20the%20cordova-azure-notification-hubs%20plugin%20in%20your%20Capacitor%20application.%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId--770737868%22%20id%3D%22toc-hId--770737868%22%3E%3CFONT%20size%3D%225%22%3EConclusion%3C%2FFONT%3E%3C%2FH1%3E%0A%3CP%3EAs%20you%20can%20see%2C%20Ionic%20developers%20have%20options%20for%20implementing%20Azure%20Notification%20Hubs%20in%20their%20apps%20using%20a%20third-party%20Cordova%20plugin.%20We%20hope%20that%20the%20sample%20applications%20we%20provide%20help%20you%20implement%20Azure%20Notification%20Hubs%20in%20your%20Ionic%20applications.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1056685%22%20slang%3D%22en-US%22%3E%3CP%3EMany%20of%20our%20customers%20use%20Apache%20Cordova%20or%20the%20Ionic%20Framework%20for%20their%20mobile%20apps%20as%20a%20way%20to%20deliver%20cross-platform%20mobile%20apps%20to%20their%20customers%20and%20employees.%20While%20Azure%20Notification%20Hubs%20doesn%E2%80%99t%20directly%20support%20these%20frameworks%2C%20Ionic%20supports%20most%20Apache%20Cordova%20plugins%20and%20there%E2%80%99s%20an%20official%20PhoneGap%20Push%20plugin%20you%20can%20use%20as%20well%20as%20a%20community-built%20plugin%20for%20Azure%20Notification%20Hubs%20apps%20running%20on%20Apache%20Cordova.%20This%20article%20shows%20you%20how%20to%20use%20these%20frameworks%20with%20Azure%20Notification%20Hubs.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1056685%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Developer%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Notification Hubs.jpg

 

Many of our customers use Apache Cordova or the Ionic Framework for their mobile apps as a way to deliver cross-platform mobile apps to their customers and employees. While Azure Notification Hubs doesn’t directly support these frameworks, Ionic supports most Apache Cordova plugins and there’s an official PhoneGap Push plugin you can use as well as a community-built plugin for Azure Notification Hubs apps running on Apache Cordova.

 

The PhoneGap Push plugin doesn’t support Azure Notification Hubs directly, but you can use it for the device-side part of the device registration process, using your app backend for the rest. I’ll describe that option later in this post.

 

The community plugin for Azure Notification Hubs is not supported by the Azure Notification Hubs team, but many of our customers use it for their production apps today. For Apache Cordova developers, the instructions included in the plugin’s readme show how to use the plugin in your apps. For Ionic developers, later in the post I’ll highlight sample applications for Ionic 3 and Ionic 4 I built using the plugin so you can see how to use it for your Ionic apps. These samples are just that: samples, provided to show you how I did it while recognizing that they might not work today based on changes in the Ionic framework and the underlying Apache Cordova (for Ionic 3 apps and Ionic 4 apps built on top of Apache Cordova) or Capacitor (Ionic 4 apps) runtime.

Using the PhoneGap Push Plugin in an Apache Cordova App

The PhoneGap Push plugin handles the process of obtaining a device’s push token from the device manufacture’s Push Notification Service (PNS). After following the instructions for adding the plugin to your Apache Cordova project, your app will have a call to initialize the plugin using code similar to the following:

 

 

const push = PushNotification.init({
  android: {},
  ios: {
    alert: 'true',
    badge: true,
    sound: 'false'
  },
  windows: {}
});

 

 

Next, you’ll add a registration event listener like the one shown below:

 

 

push.on('registration', data => {
  console.log(data.registrationId);
  var deviceToken = data.registrationId;
  console.log(data.registrationType);
});

 

 

With that in place, the value in the deviceToken variable is the unique push token for this device you’ll need to send notifications to the device using Azure Notification Hubs.

 

Send that device push token to your app backend then use the Azure Notification Hubs Installations API to register the device for notifications. You can find instructions on registering devices in Azure Notification Hubs in the Registration Management documentation.

Configuring Azure Notification Hubs in Ionic 3 Apps

Ionic 3 apps are built on top of Apache Cordova, and the Ionic team did an excellent job of enabling Cordova plugin support in Ionic 3 apps. To build an Ionic 3 app that works with Azure Notification Hubs, simply:

With the plugin in place, initialize the plugin and respond to notification events as documented in the plugin’s documentation.

 

We created a sample application demonstrating how to use the plugin in an Ionic 3 app. The sample implements an Ionic Provider for Azure Notification Hubs that manages registration and processing of notifications as they come in. When the provider has important information (like registration success or a notification message) it sends it to the application’s main form as an event notification which causes the app to update its UI.

Configuring Azure Notification Hubs Ionic 4 Apps

Ionic 4 delivered big changes for Ionic. The Ionic team made a lot of changes to the framework plus released Capacitor, their alternative for Apache Cordova. Capacitor still supports Apache Cordova, but only a subset of the existing plugins. Ionic also built many common plugins into Capacitor, so you no longer ‘need’ Cordova plugins to deliver certain functionality to your app.

 

One example of this is the Capacitor Push Notifications plugin which adds support for registering for and processing push notifications to Capacitor. If you follow the procedure to create an Ionic 4 project, add the cordova-azure-notification-hubs plugin to it, and add the code that registers for and processes notifications like you did for Ionic 3 applications, you’ll find that your application registers successfully, but never ‘receives’ any notifications.

 

What’s happening is that the cordova-azure-notification-hubs plugin is properly managing the registration process with Azure Notification Hubs, but the Capacitor Push Notifications plugin intercepts all notifications that arrive on the device, circumventing the Azure Notification Hubs SDK.

 

This means that to automatically register for and receive notifications, your Ionic 4 application must use both plugins. The cordova-azure-notification-hubs plugin to manage automatic registration, and the Capacitor Push Notifications plugin to process them when they arrive. Special thanks to Matthew Podwysocki (Microsoft) and Mike Hartington (Ionic) for figuring this one out.

 

We created a sample application that shows how to use the plugin in an Ionic 4 app. The sample implements the same Ionic Provider for Azure Notification Hubs that manages registration, but adds additional code to use the Capacitor Push Notifications plugin to process received notifications. With that in place, it’s basically the same UI and logic as the Ionic 3 sample (updated for changes in Ionic 4).

The Capacitor Push plugin also supports a similar registration event listener you can use to grab the device push token and send it to your app backend for Azure Notification Hubs registration. Doing this eliminates the need to use the cordova-azure-notification-hubs plugin in your Capacitor application.

Conclusion

As you can see, Ionic developers have options for implementing Azure Notification Hubs in their apps using a third-party Cordova plugin. We hope that the sample applications we provide help you implement Azure Notification Hubs in your Ionic applications.

4 Comments
Occasional Visitor

I need to integrate azure push notification into our ionic 4 app. We don’t use capacitor, but just cordova only. Any tip on how to do it or where should we start?

Microsoft

@MingLeung no, I'm sorry but I didn't do any testing with Ionic 4 and Cordova. I assume it works the same as Ionic 3, but I didn't do any research there. 

Frequent Visitor

@johnwargo_msThanks for the wonderful article.
I have followed this entire article and I am able to send and receive notifications in my ionic app. I have used capacitor's Push plugin and event listener for registration, grabed the device's push token and sent it to my app's backend for Azure Notification Hubs registration. I am able to receive these notification in my app through alert, but these notifications don't appear on my android's notification bar. Do I need to add anything extra for that?

Microsoft

@divyasmehta I think that depends on the type of notification you send to the device.