Did you know that the iPhone is able to detect different levels of touch depending on how hard you press? This is all thanks to 3D Touch! Check out how to add 3D Touch quick actions to your iOS apps.
Together with iPhone 6s, Apple introduced 3D Touch. This feature is able to detect different levels of touch, depends on how hard you press. It is basically a third dimension in the user interface.
3D Touch – How it Works
With this feature, the user gets access to an app’s quick actions by pressing hard on the home screen icon of the iOS application. By hard pressing a view inside an app, the user can see a preview for additional content and features.

3D Touch – how it works
Getting Started with 3D Touch quick actions
First of all, to implement 3D Touch quick actions in your iOS app, you have to define UIApplicationShortcutItems array in your app’s Info.plist file. It should look like this:
You should define one static quick action with the following parameters:
- UIApplicationShortcutItemTitle (required) is a string describing the quick action.
- UIApplicationShortcutItemSubtitle is optional text displayed below (remember it is a single line). If you haven’t added a subtitle your title will be able to be shown on two lines.
- UIApplicationShortcutItemIconType is an optional string that represents your icon in the Assets file.
- UIApplicationShortcutItemType (required) is a required string that identifies the quick action.
You can find a list of all available shortcut items with full descriptions here (Table 2).
Now, you have one 3D Touch quick action in your iOS app:

3D Touch quick action
To handle this action, you need to implement the performActionForShortcutItem method in AppDelegate.swift:
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
completionHandler(handleShortcutItem(withShortcutItem: shortcutItem))
}
You call completionHandler with a Boolean value, which you get from handleShortcutItem(). True means that you have succeeded with handling your quick actions. False means that you have not succeeded.
enum ShortcutType: String {
case print = "Print"
}
func handleShortcutItem(withShortcutItem item: UIApplicationShortcutItem) -> Bool {
guard let shortcutType = item.type.components(separatedBy: ".").last else { return false }
if let type = ShortcutType(rawValue: shortcutType) {
switch type {
case .print:
print("quick action handled!")
return true
}
}
return false
}
Here you have the method, handleShortcutItem(), that takes UIApplicationShortcutItem as an argument and returns a Boolean value depending on the success / failure of the quick action. This function checks if the passed shortcutItem is the one you are expecting. Then returns true if the type of quick action matches a type in enum ShortcutType. So, all the quick action does is print text on the console screen.
Okay, it was super easy and everything works fine. What you did was to define a static array of quick actions. And how about changing actions dynamically?
Dynamic 3D Touch Quick Actions in iOS
Here is your answer to this issue:
Once you have registered a quick action, it cannot be changed. So what you need is to set the characteristics (title and type – they are both required) to UIApplicationShortcutItem during initialization, just before registering them.
To do that, drag a button to your view and add this code to @IBAction (touch up inside).
if let bundleID = Bundle.main.bundleIdentifier {
let type = bundleID + ".DynamicAction"
let icon = UIApplicationShortcutIcon(templateImageName: "ic_add_circle_outline")
let newQuickAction = UIApplicationShortcutItem(type: type, localizedTitle: "New Dynamic Action", localizedSubtitle: nil, icon: icon, userInfo: nil)
var existingShortcutItems = UIApplication.shared.shortcutItems ?? []
print(existingShortcutItems)
if !existingShortcutItems.contains(newQuickAction) {
existingShortcutItems.append(newQuickAction)
UIApplication.shared.shortcutItems = existingShortcutItems
}
} else {
print("bundle Id is missing")
}
You create newQuickAction with a new icon and type which is bundleID + name and title. Then, by assigning your action to shortcutItems in a shared instance of UIApplication class you register it. Finaly, to be prepared for a new coming action, you should also change the enum ShortcutType and handleShortcutItem method:
enum ShortcutType: String {
case print = "Print"
case new = "DynamicAction"
}
func handleShortcutItem(withShortcutItem item: UIApplicationShortcutItem) -> Bool {
guard let shortcutType = item.type.components(separatedBy: ".").last else { return false }
if let type = ShortcutType(rawValue: shortcutType) {
switch type {
case .print:
print("quick action handled!”
return true
case .new:
print("dyamic quick action handled!")
}
}
return false
}
As a result, you have two actions now! It should look exactly like this:

3D Touch – static and dynamic quick actions
Summary: 3D Touch Quick Actions Tutorial
Remember that after the installation of an app, the system will register only static quick actions. Dynamic quick actions in iOS can be registered at runtime.
An important fact is that the system limits the number of quick actions. Static actions are displayed first and if there is still some space then an appropriate number of dynamic actions are shown. Keep that in mind.
Apple gives some tips on how to use this quick actions. For example, every quick action should have an important value for the users, a clear title and a matching icon (but not an emoji). You shouldn’t use quick actions for ease of navigation or notifications also. See more at iOS Interface Guidelines.
Check our next tutorial: 3D Touch Peek and Pop Tutorial.
Popular posts

From Hype to Hard Hats: Practical Use Cases for AI chatbots in Construction and Proptech.
Remember the multimedia craze in the early 2000s? It was everywhere, but did it truly revolutionize our lives? Probably not. Today, it feels like every piece of software is labeled "AI-powered." It's easy to dismiss AI chatbots in construction as just another tech fad.
Read more
Fears surrounding external support. How to address concerns about outsourcing software development?
Whether you’ve had bad experiences in the past or no experience at all, there will always be fears underlying your decision to outsource software development.
Read more
What do you actually seek from external support? Identify what’s preventing you from completing a project on time and within budget
Let’s make it clear: if the capabilities are there, a project is best delivered internally. Sometimes, however, we are missing certain capabilities that are required to deliver said project in a realistic timeline. These may be related to skills (e.g. technical expertise, domain experience), budget (hiring locally is too expensive) or just capacity (not enough manpower). What are good reasons for outsourcing software development?
Read more

