Quick Actions in iOS

for instant navigation

Karthikeyan T
IVYMobility TechBytes
5 min readMar 28, 2020

--

Quick actions are the most convenient way to do useful or any app-specific actions from the Home screen.

In this post, I explained about the quick actions and not about widgets.

Quick Actions are available on all devices running iOS 13 or later.

A list of available Quick Actions are displayed on a long-press or force touch(if available) on the app icon.

The list position depends on the app’s position on the Home screen.

Each Quick Action has a title, subTitle (optional)and image icon (optional)

Every app can provide a maximum of four quick actions. If it exceeds four, then the first four quick actions only visible to the user. Each app has its default system quick action like “Edit Home Screen”, “Share App”, “Delete App”.

Here, the title and subtitle are always left-aligned for left-to-right languages and vice-versa.

Guidelines by Apple for implementing Quick Actions.

  1. Create Quick Actions for useful and creative tasks.
  2. Avoid Quick Actions for the action involves complex navigation to the destination screen.
  3. If the Quick Actions configured dynamically, then make sure it won’t make any unpredictable changes.
  4. Each Quick Action title should briefly and clearly expressed.
  5. Don’t use quick actions for notification.
  6. Provide a recognizable icon for each quick action. You can use system icons as well as custom icons.
  7. Restrict the usage of emoji since it is not monochromatic and it will not align properly.

Quick actions can be configured either static or dynamic.

  1. Static actions at build time are visible to the user when they install or update the app. Also, if the quick actions that are appropriate for your app never change, define them as static quick actions in the project’s Info.plist file
  2. Dynamic actions at run-time are visible to the user once the app launched at least once. Here, the actions can be configured based on the user’s behaviour.

Define Static Quick Actions

Quick Action can be added statically UIApplicationShortcutItems array in the app’s Info.plist file. Each element in the array is a UIApplicationShortcutItem dictionary which represents the quick actions. It contains the following entries

  1. UIApplicationShortcutItemTitle: A required string that is displayed as the title of your action. It will be displayed as a maximum of two-line if necessary. Additionally, we can localize the title if needed.
  2. UIApplicationShortcutItemSubtitle: An optional string that is displayed as a subtitle of your action and displayed below the title. It will be displayed as a single line. Also, we can localize the subtitle if needed.
  3. UIApplicationShortcutItemIconType: An optional string for an image icon that depicts what kind of Home Screen Quick Action Icons should be used for this shortcut.
  4. UIApplicationShortcutItemIconFile: An optional string for a custom image icon name. The provided image named will be loaded from the app’s bundle and will be masked to conform to the system-defined icon style. Apple recommends that the custom image icon should be square, single-colour, and 35x35 points.
  5. UIApplicationShortcutItemUserInfo: An optional app-specific information that can be provided for use when the app performs the quick action.
  6. UIApplicationShortcutItemType: A required unique string that passed to your app when a user taps the quick action. It is used to identify the type of quick action to perform.
Snapshot of Info.plist file shows how to add quick action statically.

If you are feeling slow in typing, then copy the below content, open the Info.plist as Source code and paste the same.

<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemTitle</key>
<string>Search</string>
<key>UIApplicationShortcutItemSubtitle</key>
<string>by product name</string>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypeSearch</string>
<key>UIApplicationShortcutItemType</key>
<string>QuickAction.Search</string>
</dict>
<dict>
<key>UIApplicationShortcutItemTitle</key>
<string>Saved Items</string>
<key>UIApplicationShortcutItemIconFile</key>
<string>SavedItems</string>
<key>UIApplicationShortcutItemType</key>
<string>QuickAction.SavedItems</string>
</dict>
<dict>
<key>UIApplicationShortcutItemTitle</key>
<string>Cart</string>
<key>UIApplicationShortcutItemIconFile</key>
<string>cart.png</string>
<key>UIApplicationShortcutItemType</key>
<string>QuickAction.Cart</string>
</dict>
</array>

Define Dynamic Quick Actions

It can be configured by setting the shortcutItems property of UIApplication shared instance to an array of UIApplicationShortcutItem objects. It looks like UIApplication.shared.shortcutItems = [shortcutItem]

Adding Quick Actions dynamically
Deleting Quick Actions dynamically

In the above example, quick action has been removed (if available) before adding the quickAction to avoid redundant.

Handling Quick Action

When the user triggers a Home screen quick action, your app is notified in one of these ways:

  1. If the app is not in running state, then the details of the shortcut item is passed through the launchOptions parameter of the method application(_:didFinishLaunchingWithOptions:) .
  2. If the app is in running state, then the following method application(_:performActionFor:completionHandler:) in the AppDelegate will be triggered.
Handling Quick Actions, If the app is not loaded
Handling Quick Actions, If the app is already loaded

I don’t always go with straight string comparison. So Enum type is used for comparison.

Enum type used to handle String
Final Output

Facts about Quick Action

  1. If the App is just installed, then only the static quick actions (if available) are displayed on pressing the app icon on the home screen.
  2. After the app’s first launch, dynamic actions (if available) are displayed on pressing the app icon on the home screen.
  3. If the app is updated, then the old quick actions only visible to the user(if available) until the app launched after the update.
  4. But it is reported that the above said scenario can be solved by providing the app version in the userInfo params of a Quick Action.
  5. If the quick action configured statically and dynamically, then the dynamic action is given high priority. If it has space to accommodate, then the static quick action is added at the end.

Get the full source code at GitHub

References: Apple Documentations

Find it a good read?

Recommend this post (by clicking 👏 button) so other people can see it too… reach me on LinkedIn Karthikeyan

--

--