29 January, 2017

IOS: How to enable ForceTouch support (1/2)

The ability to accelerate a users interaction with your app by the virtue of ForceTouch - has proven surprisingly useful to me and I’ve decided to investigate how that is achieved.

As this is a fairly large topic - it has been broken down into 2 separate posts. The first one (this post) addresses the UI declaration. The second post will address the code behind the UI-items.

First of - how do you define the support? You need to define a new entry in the custom section of your info.plist file (that ultimately will render in your project settings). To my surprise - this was actually not an entry that comes up in the drop down list when adding a new row. But, luckily you are allowed to add it by hand (just type the name).

Changes to info.plist (the project file)

  • Select the info.plist file in the project navigation window.
  • Right click on the blank area and select Add Row
  • You cannot select a properly named item - so name the new entry (just write the name): UIApplicationShortcutItems
  • Set the datatype = Array
  • This array will hold a number of Dictionary objects that each define a ShortCutItem (the force touch items presented when pressing the application icon)

To add the dictionary items to the array - you can do so using the Xcode editor or using a conventional text editor (he plist file is just an xml-file). Finally - as you can see from the below images the entries in the plist file will give you the UI.

All 3 elements in each dictionary should be there - the one connecting the dots between UI and code is the UIApplicationShortcutItemType value. This must be unique. Conventionally, this is achieved by combining the bundleID with a string (in the below example ".First" or ".Second").

info.plist open in Xcode:

info.plist file opened in Visual Studio Code (just a text editor):

The end result when force-pressing the app icon is seen here:

The next question obviously is - okay, how do I interact with the code when these items are pressed? That's the subject of post 2...

No comments:

iPhone/XCode - not all cases are equal!

This bit me! Having made some changes to an iPhone application (Obj-C); everything worked fine in the simulator. But, when deploying the s...