Using Application Shortcuts

      No Comments on Using Application Shortcuts

With iPhone 6s came the 3D touch, and with it we got a few more options to interact with the users. In this short blog post we’ll examine one of those options called ‘Application Shortcuts’, or sometimes called ‘Home Screen Quick Actions’, we’ll call them application shortcuts, because it’s shorter.

In a few words, application shortcuts is a menu that is available to you when you force touch on an application icon. If you have an iPhone 6s (or 6s plus), press really hard on an app like Facebook, and you’ll see what I mean, make sure you have force touch enabled, or you might break the screen trying to display the menu 🙂 ).

Example

Implementing application shortcuts is really simple, and we’ll go through a basic example of dynamic application shortcuts that you will be able to use in your apps and expand on it as you see fit.

You can create up to four menu items, and each item is of type UIApplicationShortcutItem. All we have to do is create an array of our shortcut items, and set it on our shared application.

First lets define an enum for our menu items, so to make it extensible, like so:

With our enum in place we can create an array of menu items:

Now we have an array of shortcut items, and we can set it on our shared application:

If you build and run your app on a device you can see the menu by force touching on the app icon. As shown on the next image:

All that’s left is hookup the delegate callback and process the selected item. We’ll implement a delegate callback in the app delegate:

In my implementation you will se an alert popping up to give you some visual feedback that everything works, obviously you won’t need this in your implementation. I’m using a shortcut manager to generate and process menu items, we’ll see the ‘process shortcut item’ implementation in a moment. At the end of the function you should call the completion handler with a boolean value, true if your action succeeded and false if it failed.

In the shortcut manager we have a function that will process selected menu items:

In this function you would perform your custom actions, of course, this depends on the nature of your application, some of the actions you could perform might be displaying a view controller, opening another app, opening a url, whatever comes to your mind.

This has been a short and fun post, I hope you’ll find something useful in it, you can find the example project on my GitHub account, feel free to use it.

As always, have a nice day 🙂

Dejan.

More resources

0

Leave a Reply