INSANE NOTIFICATIONS A N E A S Y WAY T O H A N D L E P U S H N O T I F I C AT I O N S W I T H X A M A R I N

Przemysław Raciborski, In’saneLab

https://github.com/thefex/Insane.Notifications

W H AT I S P U S H N OT I F I C AT I O N ? PUSH Notification is a modern way thanks to which application publishers can notify their users about some kind of action at any time. Users do not need to have the application opened to receive notifications – which gives us (developers) an incredible tool to keep our user-base active.

INSANE NOTIFICATIONS

I S S U E S W I T H M U LT I - P L AT F O R M P U S H Each platform has it is own concept of “Remote Notification Server”. Android uses GCM/FCM, iOS – APNS, Windows Mobile – WNS. Therefore implementation on each platform is completely different. This brings us some thoughts, can we at least partially: share code related to registering to PUSH Notification Provider? share code related to presenting and handling user-action response of PUSH Notifcation? Unfortunately, with “classic” approach presented in official Xamarin/Microsoft samples it is not possible, which in the end results in thousands of duplicated lines of code across different Mobile Projects.

INSANE NOTIFICATIONS

I N ’ S A N E L A B G I F T I N S A N E N OT I F I C AT I O N S L I B R A R Y Most of the apps we develop at In’saneLab have PUSH Notifcations feature and we could not stand wasting time on writing almost the same code over and over again. Therefore, we decided to create multiplatform Xamarin library to simplify this process – InsaneNotifcations.

INSANE NOTIFICATIONS

I N S A N E N OT I F I C AT I O N S F E AT U R E S Works for Xamarin.Android, Xamarin.iOS, UWP Remote Notifications support for GCM (FCM is on roadmap), APNS and WNS Notification Presenter – concept based on MvvmCross View Presenters – small, modular classes that simplify handling and displaying received PUSH Notification on each platform Handling edge cases – for example: automatic re-registration to background service when app is updated/device is rebooted on UWP All features have corresponding package with support for MvvmCross Framework Local Notifications are not supported yet – however you can use “Notification Presenter” to speed up PUSH handling development INSANE NOTIFICATIONS

I N S A N E N OT I F I C AT I O N S F E AT U R E S W I T H B AC K E N D - B A S E D P U S H Sample works by connecting to REST API that uses Azure Notification Hub. Sample C# WebAPI Backend project (used in current sample) is available here: https://github.com/thefex/Insane.Notifications/tree/master/Insane.Notificat ions/Samples/PUSH/Insane.PushSample/Insane.PushSample.Backend

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S - P O RTA B L E 1. Implement IRemotePushRegistrationService – Backend based implementation should call your REST API method that registers/unregister your device from PUSH Service. Sample implementation link 2. Implement IPushTagsProvider - it should return tags (Notification Hub concept) for which user is/should be currently connected. In case you are not using any Notification Hub tags – your implementation can return an empty list.

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S - P O RTA B L E 3. Implement model class/classes that represents the model of data you want to PUSH 4. Create those services as a singleton (one instance across application) – perhaps by using your Dependency Injection Container MvvmCross sample link 5. Use INotificationsService and call Subscribe/Unsubscribe methods when appropriate (after user logs in/logs out?). It will automatically call a registration process on each platform. Code sample link

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – A N D RO I D (G C M ) 1. Add assembly attribute [assembly: UsesPermission(Name = "@[email protected] on.C2D_MESSAGE")] 2. Add Android Service which inherits from InsaneGcmService You should implement GetPushJsonData method – it should extract json data which models your PUSH Notification. Code sample link 3. Add BroadcastReceiver class which inherits from GcmBroadcastReceiver (copy-paste from sample) Code sample link

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – A N D RO I D (G C M ) 3. Implement IRemoteNotificationIdProvider This interface is used to determine the type name of your PUSH Notification. We can send notifications of different types, the example: You have a new Facebook connection (someone accepted your friend request), Someone liked your photo on Facebook We have to somehow select a “Notification Type” from data we have in PUSH Notification. The easiest way is to embed push type in notification json content. Code sample link

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – A N D RO I D (G C M ) 4. As in Portable, register your services as singletons. INotificationsService to GcmRemotePushNotificationService, IRemoteNotificationIdProvider to implementation you have created in step 3 IRemoteNotificationsPresenter to RemoteNotificationsPresenter Code sample link

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – A N D RO I D (G C M ) 5. Implement RemoteNotificationHandler for each PUSH type. If you want to show a standard Android PUSH – inherit from: DroidRemoteNotificationHandler Implementation will take care of handling/displaying PUSH Notification. Each handler class should have attribute: [RemoteNotificationHandlerAttribute(”push_type_returned_in_remote_noti fication_id_provider_implementation")] Code sample link

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – A N D RO I D (G C M ) 6. Your activities should have two additional lines of code: “Intent?.Extras?.HandlePushDataIfExists();” – in the end of OnCreate(Bundle) method „intent?.Extras?.HandlePushDataIfExists();” – in the end of OnNewIntent(Intent intent) method Those lines take care of background/foreground PUSH activation. Code sample link

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – I O S ( A P N S ) 1.

As in Android – you have to implement IRemoteNotificationIdProvider. Sample implementation which is adjusted to Apple Push Notification json data template can be found here.

2.

Override two methods in AppDelegate – “void RegisteredForRemoteNotifications”, “void FailedToRegisterForRemoteNotifications” like in Code Sample.

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – I O S ( A P N S ) 3. Register your services as singletons as you would do usually. After that – call PushiOSNotificationsSetup.Initialize(IIOSRemoteNotificationsPresenter instance); - and you are done J RemotePushNotificationService to iOSRemotePushNotificationService INotificationsService to RemotePushNotificationService IRemoteNotificationIdProvider to your implementation IIOSRemoteNotificationsPresenter to iOSRemoteNotificationPresenter Code sample link

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – I O S ( A P N S ) 4. Implement “Notification handler” for each Notification type. (like in Android sample) APNS supports four types of notifications: Toast Notification (standard toast shown automatically) – to support this kind of notification your handler should implement IIOSAlertNotificationHandler interface Code sample link Badge Notification (badge on app icon) – your handler should implement IIOSBadgeNotificationHandler interface

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – I O S ( A P N S ) Sound Notification (sound played) – your handler should implement IIOSSoundNotificationHandler interface RAW Notification (does not have any automatic action, implementation is totally up to you) – your handler should implement IRemoteNotificationHandler interface Make sure that your Handler class has a “[RemoteNotificationHandler(“notificationIdWhichShouldMatchWit hYourRemoteNotificationsIdProvider”)] attribute. Additionally - if you want to handle user actions – your handler should inherit from iOSRemoteNotificationTapAction.

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – U W P ( W N S ) 1.

WNS (Windows Notification Service) supports four kinds of notifications templates: a) Badge Notification (badge on app tile) – xml-based notification template b) Tile Notification (update application tile) – xml based notification template c) Toast Notification (standard application toast) – xml based notification template d) Raw Notification (your custom logic) – notification template can be an json

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – U W P ( W N S ) As we have four different notifications content – we should implement four interfaces. IRemoteNotificationIdProvider – as in Android/iOS – returns Notification ID for RAW Notification IToastRemoteNotificationHandlerIdProvider – returns notification ID for Toast Notification, code sample ITileRemoteNotificationHandlerIdProvider – returns notification ID for Tile Notification IBadgeRemoteNotificationHandlerIdProvider – returns notification ID for Badge Notification

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – U W P ( W N S ) 2. As usual – you should implement Notification Handler for each Notification Type you plan to push. a) Toast Notification Handler should inherit from ToastRemoteNotificationHandler and it should have [ToastRemoteNotificationHandler(“notificationId”)] attribute, code sample b) Badge Notification Handler should implement IBadgeRemoteNotificationHandler and it should have [BadgeRemoteNotificationHandlerAttribute(“notificationid”)] attribute

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – U W P ( W N S ) c) Tile notification handler should implement ITileRemoteNotificationHandler and have [TileRemoteNotificationHandler(“notificationId”)] attribute d) Raw Notification should implement same interface as iOS/Android IRemoteNotificationHandler + it shoud have [RemoteNotificationHandler(“notificationId”)] attribute If you want to handle “Tap on push action” on your RAW notification you should implement IRemoteNotificationTapAction as well. If you are going to display “Toast” notification – make sure you provide “LaunchArgument” using LaunchArgumentSerializator.SerializeLaunchArgument(..) helper.

INSANE NOTIFICATIONS

I M P L E M E N TAT I O N S T E P S – U W P ( W N S ) 3. Add necessary methods in your Application class (App.xaml.cs). On the end of “OnLaunched” method you should call PushServicesExtensions.SetupNotificationsIfNeeded(..) method On the end of “OnActivated” method you should call PushServicesExtensions.HandlePushActivation(..) method On the end of “OnBackgroundActviated” method you should call PushServicesExtensions.HandlePushRelatedBackgroundActivation(..) method Check code sample. 4. Register your PUSH related services as singletons. Code sample is available here.

INSANE NOTIFICATIONS

A P P E N D I X - FAQ 1. 2.

Is FCM (Firebase Cloud Messenging) supported? Unfortunately not – but it is in the library roadmap. Please, use GCM until that. Can I use Azure Notification Hubs without Backend? Sure. InsaneNotifications Remote Notifications have been developed to support different providers. (as long as they use WNS/GCM/APNS) Simply use custom IRemotePushRegistrationService – instead of using “REST API” as in sample app use Microsoft.Azure.NotificationHubs library.

INSANE NOTIFICATIONS

A P P E N D I X - FAQ 3. How can I configure Azure Notification Hub to work with my apps? Please check official Microsoft Documentation, https://docs.microsoft.com/en-us/azure/notification-hubs/notificationhubs-android-push-notification-google-gcm-get-started - GCM https://docs.microsoft.com/en-us/azure/notification-hubs/notificationhubs-ios-apple-push-notification-apns-get-started - APNS https://docs.microsoft.com/en-us/azure/notification-hubs/notificationhubs-windows-store-dotnet-get-started-wns-push-notification - UWP

INSANE NOTIFICATIONS

A P P E N D I X - FAQ 4. How should sent PUSH template look like? a) b)

c)

APNS template is described here. It is json data wrapped into ”aps” key. GCM template is simple json data wrapped into “data” key. { “data” : { jsonDataVisibileToYourApp } } WNS default templates are: - Toasts XML Documentation - Badge template – - Tile XML Documentation - RAW Notification – pure text, if you are using it with InsaneNotification please use JSON data format. INSANE NOTIFICATIONS

A P P E N D I X - FAQ 5. I am using standard UWP Toast notifications but my Tap Action handler does not work when the application is closed. It is caused due to the complex nature of UWP Notifications. There are two solutions to the issue: a) Pass a launch argument at the top of your Toast PUSH XML. It should be in such format: “YourNotificationHandlerId$INSANELAB_NOTIFICATIONS$base 64ofYourJsonDataParameters”

INSANE NOTIFICATIONS

A P P E N D I X - FAQ b) Use RAW notifications all the time as it is easier to handle. In RAW Notification Handler display Toast using Microsoft.Toolkit.Uwp.Notifications helper library. Your toast “LaunchArguments” property should be set to: LaunchArgumentSerializator. SerializeLaunchArgument(your notification handler id, your push data model object which will be passed to Tap Action handler) It’s pretty complicated but that’s the simplest workaround for the complex nature of UWP Background Notification handling.

INSANE NOTIFICATIONS

DZ I Ę K U J Ę Z A U WAG Ę ! Z A P R A S Z A M Y N A KO L E J N E S P O T K A N I A ! P R Z E M Y S Ł AW R A C I B O R S K I

insane notifications - GitHub

Each platform has it is own concept of “Remote Notification Server”. Android ... Page 10 ... If you want to show a standard Android PUSH – inherit from:.

800KB Sizes 6 Downloads 186 Views

Recommend Documents

Alerts, Notifications and Warnings Final.pdf
Section 255 of the Telecommunications Act of 1996. • requires telecommunications products and services to be accessible to. people with disabilities. Page 3 of ...

Various Notifications for 256 vacancies.PDF
Sep 30, 2016 - A Bachelor's Degree or Diploma in Civil Engineering of a. University in .... PDF. Various Notifications for 256 vacancies.PDF. Open. Extract.

interactive notifications sale offering services
The enclosed material supports an offer for sale of the described patent and/or application portfolio. The information contained in this document is provided in ...

Remind Notifications for Olympus Jr High School.pdf
Remind Notifications for Olympus Jr High School.pdf. Remind Notifications for Olympus Jr High School.pdf. Open. Extract. Open with. Sign In. Main menu.

Notifications-Andhra Pradesh-01 (1).pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item.

Finding the cause of acute kidney injury: Which ... - Insane Medicine
sepsis,6 or contrast-induced nephropathy,7 and in those .... frActiOnAL eXcretiOn Of ureA VS. frActiOnAL ... renal azotemia, prerenal azotemia plus diuretic.

Push Notifications help Jumia reverse cart ... Developers
on mobile browsers, Jumia looked to progressive web app technologies like. Push Notifications to solve their problem and re-engage mobile users who.

A Compilation of all MCA circulars and notifications ... -
notification dated. 12.9.2013. Statement to be annexed to notice shall be under Sec. 102 for statements after 11 Sep 2013. Circular. 2013 General Circular No.

GitHub
domain = meq.domain(10,20,0,10); cells = meq.cells(domain,num_freq=200, num_time=100); ...... This is now contaminator-free. – Observe the ghosts. Optional ...

GitHub
data can only be “corrected” for a single point on the sky. ... sufficient to predict it at the phase center (shifting ... errors (well this is actually good news, isn't it?)

Torsten - GitHub
Metrum Research Group has developed a prototype Pharmacokinetic/Pharmacodynamic (PKPD) model library for use in Stan 2.12. ... Torsten uses a development version of Stan, that follows the 2.12 release, in order to implement the matrix exponential fun

Untitled - GitHub
The next section reviews some approaches adopted for this problem, in astronomy and in computer vision gener- ... cussed below), we would question the sensitivity of a. Delaunay triangulation alone for capturing the .... computation to be improved fr

ECf000172411 - GitHub
Robert. Spec Sr Trading Supt. ENA West Power Fundamental Analysis. Timothy A Heizenrader. 1400 Smith St, Houston, Tx. Yes. Yes. Arnold. John. VP Trading.

Untitled - GitHub
Iwip a man in the middle implementation. TOR. Andrea Marcelli prof. Fulvio Risso. 1859. Page 3. from packets. PEX. CethernetDipo topo data. Private. Execution. Environment to the awareness of a connection. FROG develpment. Cethernet DipD tcpD data. P