As the competition in mobile app industry is growing, usability sets a stage for new demand model. A device like iPhone is friendly, accessible and easy to use. This means, it can predict your needs and be handy always. Due to the increasing demand of wide screen devices, making use of lesser motion has become an interesting thing for developers.
Apple has introduced a set of quick actions to the app icon that allow users to select a quick action. Once the app receives quick action message, the app activates or launches quickly. The 3D touch technology was introduced in iPhone 6S and 6S+ models. This technology is equipped with a tap force sensitive display that could measure the pressure on screen. As the user press an app icon on the Home Screen, he will get a quick access to some of the functionalities in the app.
In order to support whether the device supports 3D technology or not, developers have to know everything in detail about force Touch capability values. The 3D technology allows developers to add quick actions to their iOS apps. Neglecting that would be one of the biggest mistakes developers make. However, these features can be added quickly.
In this post, I am going to share how to add 3D quick actions to your iOS apps.
Quick actions on Home Screen
Quick actions can be static as well a dynamic. You can define static actions at the time of building an app. They are visible to the user when the app is installed or updated. On the contrary, dynamic actions can be added at run time so the user will see them once they have launched the app. Each action will have a title and icon.
There are dozens of shortcut items that help you add 3D actions quickly. Apple made the below 3D Touch APIs available for developers.
How to add static actions to Home Screen?
As said there are different options that are visible when the application icon is pressed. Define the static action in info.plist. For this, you need to first create a new row in your plist and give it the key UIApplicationShortcutItems and set the type to Array. You can even add a dictionary for every quick action. Now, select the row that you have created and add new row to the array. Set the type to Dictionary – where you have to add rows with specific keys and values. You should define the quick actions with the below parameters –
How to add Dynamic actions to Home Screen?
Dynamic actions can be added to the UIApplication application object in shortcutItems property. There are two methods of creation.
Method 1 –
userInfo: [AnyHashable : Any]? = nil)
The above method creates a home screen dynamic quick action with a header and optional subheader and user info dictionary.
Method 2 –
Convenience init(type: String,
This method creates a home screen dynamic quick action without any icon. Next, you can run your app and test to see if the quick actions are formatted the way you want them to look. The next step is to develop a device that supports 3D touch.
The UIKit peek and pop APIis used to preview the content quickly and transition to it. New methods in ViewController registration allow notifications as to whether it is going to be used by 3D touch. The system will register static actions after installing the app, while it will register quick actions at runtime.
How to handle shortcuts?
You can handle the shortcuts by adding the enum and properties. If you don’t want to use enum, make sure that it matches the UIApplicationShortcutItemType values entered in the info.plist.
When the user chooses one of the quick action shortcuts, the system launches the app and calls the PerformActionForShortCutItem method in the app.The system expects you to call the completion handler once the quick action you have handled is succeeded. The ShortCutIdentifer function exits if the shortcut is not recognized. To choose the right tab in the TabBar, select TabBarItemForIndeitifer based on the identifier.
The next method is calledapplicationDidBecomeActive that is called with didFinishLaunchingWithOptions during the first launch of your app. To avoid handling quick action multiple times, you need to check willFinish or didFinish methods to see if there is quick action, handle it and return false. Returning false tells the system that not to call PerformActionForShortCutItem. You need to look into the launch options dictionary to detect if the system launched the app or not.
When the user chooses one of the quick actions, the app launches the app and calls the PerformActionForShortCutItem method.
Finally, you need to handle the shortcut app and link the user into proper view controlled within the app.
The system limits the number of quick actions. Remember that static actions are displayed first and if there is still some space – then dynamic actions are shown.
Quick actions can be used to access a certain part of app or trigger an action. However, every quick action should have an important value for the users, besides a matching icon and clear title. Make sure that the quick actions are not used for navigation or notifications.
As developers are getting to know the benefits of 3D technology, it will become a staple. At Promatics, we are looking forward to unlock the true potential of 3Dtouch development to make mobile apps more usable.
Promatics is an ISO 9001:2008 certified offshore web and mobile application development company with a strong team of 100+ highly skilled IT experts delighting SMEs across USA, Europe and APAC. Our services and solutions help clients to achieve tangible business value and remain competitive in today’s evolving marketplaces.