Enhancing your Xamarin Forms app with 3D Touch

So you want to add 3D touch support to your awesome Xamarin.Forms app? Fear not, it’ totally possible (well, in part anyway).
The Peak and Pop feature is unfortunately not available since you need to override theTraitCollectionDidChange method in a ViewController. And, as you most likely know, there is no such thing as ViewControllers in Xamarin.Forms. This is a good exemple of the limitations of this platform. As stated by Xamarin, Forms is best for simple apps that require little platform-specific functionality.

You can, however, easily add support to 3D Touch Quick Actions since the implementation for those resides in the AppDelegate.cs file.

There are two ways to declare quick actions: statically, via the “Info.plist” file or dynamically, by code. It’s also possible to have a mix of statically and dynamically declared quick actions.

The folks over at Xamarin have made a pretty good tutorial on how to implement the functionality for your Xamarin.iOS app. I’m not going to repost it here as the Xamarin Forms implementation is no different.

As an example, here is what my AppDelegate.cs file looks like after implementation:

The Constants.QuickActions.Action# constants should be the same that you used when you declared your Quick Actions (ex: com.company.appname.action1). As I’m following the MVVM pattern, I’m also using a (custom made) NotifierService that will notify the subscribed ViewModels that the user triggered a Quick Action. Upon being notified, they will handle most of the work (navigating to another view, etc.)

 Localizing Static Quick Actions

To localize your statically defined quick actions, you need to add a “InfoPList.strings” file in your Resources/[languageCode].lproj folder.


This is where you will translate your quick actions title. For a Spanish localization, it should look something like that :

“QuickAction1Title”=”Mi acción 1”; //My action 1
“QuickAction2Title”=”Mi acción 2”; //My action 2
“QuickAction3Title”=”Mi acción 3”; //My action 3

And then, in your “Info.plist” file, you simply use the localization key instead of hardcoding the string, like so:

That’s all there is, really. Enjoy your new 3D touch enhanced app!

Dernières publications

Laissez un commentaire