Introducing Crosslight Push Registration Service

First of all, happy new year to you all! To kick off the new year, we are pleased to share several exciting new stuff with you. Since version 2, Crosslight has introduced cross-platform push notification support, including the client platforms (iOS, Android, Windows) and the server-side messaging. Not only that, we also implemented the push features to the Crosslight business templates, so you can configure and enable it very quickly.

As our customers build more apps with Crosslight, we’ve frequently received questions about more advanced usage of push notification, and more to the way how the push registration can be customized further. For instance, the initial implementation supports push registration only in startup, while many scenarios demand registration to happen during successful user login.

To accomodate these scenarios, we introduced a new service called PushRegistrationService built into the Crosslight App Framework. Read on.

Push Registration Made Easy

Implementing push registration isn’t a straightforward task, even with the availability of cross-platform push notification services at your fingertips. Typically, you have to store the device token to your own database presumably via REST service, then store the record locally so your app doesn’t end up registering the same device multiple times. Fortunately, the new push registration service has encapsulated all these processes into functions that you can call at your convenience — no more tedious, redundant code.

To give you a preview, the previous dozens line of code to handle registration are now only a couple line of code.

Notice that we’ve also added a new property named EnablePushNotification in AppSettings, so you can easily turn this feature on or off — with the convenience of a property set.

When receiving the device token from the Platform Store, all you need to do now is simply calling the provided SaveDeviceTokenAsync and RegisterDeviceTokenAsync which will do the local caching and device token registration to the app’s server. See the code snippet below.

Pretty neat, isn’t it?

If you would like to extend or customize the push registration service, it’s easy to do it by yourself. The registration service conforms to the Crosslight service architecture and can be easily replaced through service provider registrar at any point in your app.

User-based Push Registration

In addition to the new registration service, we have also added support for user-based push registration in this update. In the upcoming updates to the business templates, we have provided a comprehensive boilerplate for the user-based push registration support which include:

  • Enhancements to the CrosslightDb by adding UserId column to the DeviceToken table.
  • Introduce a new property in AppSettings called PushRegistrationMode, with possible values: OnAppStart and OnUserLogin. This allows you to change the registration timing with just a  property set.

To make the implementation easy, we introduced a new UserChanged delegate event which will be consistently and reliably called everytime a user has changed. This allows us to streamline all user-dependent tasks in this event delegate, making the application easier to maintain and extend in the long run. In contrary, without the event, you will have to write code in multiple places in the ViewModel to anticipate and respond to the user changes.

Here’s a code snippet of how the UserChanged event is implemented, along with the user-based push registration implementation.

As seen above, the OnUserChanged method is the best entry point for user-dependent task which will be called reliably during registration, first login, automated login (second launch), as well as logout. Of course, you can feel free to put any user-initialization code in the above method.

Push Notification Support for iOS 8

Still in the push notification context, this update also ships with improved push notification service for iOS platform, specifically including user notification support introduced in iOS 8. Note that the service remains backward compatible with iOS 7.

On the server-side, the push messaging for Apple Push Server has also been enhanced to use TLS protocol for better security and delivery rate. This change reflects Apple’s documentation which state that SSL 3.0 support has been dropped in favor to TLS.

Updated Samples

To demonstrate the new services, features and design patterns introduced in this release, we have updated our samples with best practice to implement user-based push registration. Check out the updated OSSyncSampleFromPNS sample from the enhanced-sync-push branch.

The sync sample is one of the most comprehensive samples that shows a number of features working in harmony together. In addition to the push registration revamp in the client-side, we have also improved the overall performance of data synchronization service. In particular, on the server-side, the app’s controller is now enhanced to notify changes the same users but excluding the originating device itself. This is an interesting improvement that we believe you should check out and apply necessarily in your apps.

Download Today

Download the latest Crosslight nightly build (3.0.5000.180) today which is currently available from our Git server. To learn the complete changes made in this update, please refer to the release notes.

The final build for Crosslight 3 Update 2 will be available later this month. A new installer will be also made available at the same time which includes the updated business project templates and Crossilght item templates for iOS Unified.

Note: Due to the major revamp of push registration implementation, we highly recommend you to upgrade your projects to leverage the new push registration service for best reliability and stability. In order to do so, ensure you make changes to the implementation completely by reviewing the changes in the commit we did to our sample.

In the next post, I will share many exciting new features and improvements that we’ve done in data access, particularly the synchronization service. Stay tuned!

Best,
Jimmy

 

Leave a Reply