How backward-compatibly write NotificationServices in Unity

In Unity 5.0 they not only deprecate UnityEngine.NotificationServices, but we make it obsolete. The correct way to go now is to call UnityEngine.iOS.NotificationServices. I want to make a shared library that works for both Unity 4.6.x and 5.x (notice that I might not be able to get #UNITY_VERSION_NUMBER because it’s a library). How can I achieve this?

There probably isn’t a good solution. The best solution I can recommend, is to use two different assemblies, one for each Unity version.

If you need to use one assembly for both Unity versions, you might be able to do a run-time check of the Unity version like this:

If you need a compile-time check though, you don’t have many options. It is possible to leverage the API Updater for this purpose. You could continue to use only the 4.6 API, and the API Updater should modify the code in your assembly when it is used in a 5.0 project to use the new API. This feels like a bit of a hack, but I believe that it will work.

You can make use of UNITY_5 macro which will work for all Unity 5 versions.

Here is how we used in Cross Platform Native Plugins , which is backward compatible.


using LocalNotification = UnityEngine.iOS.LocalNotification;

using NotificationServices = UnityEngine.iOS.NotificationServices;