Thoughts on making a single NotificationHandler.cs for both Android and iOS

I was thinking of making a singular NotificationHandler.cs that would handle both iOS and Android notifications.

My reasonings are:

  1. Only the new NotificationHandler.cs will have the #if UNITY_ANDROID/IOS preprocessor directives, and no other script will need to have them, including the MainMenu.cs file.
  2. We can write a single ScheduleNotification() function that can be called anywhere without manually filtering device type.

The downside is having a long ScheduleNotification() function with both the Android and iOS versions of the function, but they can also be broken down into two separate private functions. I’m not sure how this would affect performance, but I would assume it would make working in a team easier, since others wouldn’t have to guess how to use the two different classes.

There’s no reason you can’t make a unified NotificationHandler. As long as the code in the NotificationHandler properly surrounds system specific codes with #if declarations, you should be fine.

Privacy & Terms