Mobile Applications Press Releases

Promatics Technologies shows how to build 3D quick actions in your iOS apps

Promatics Technologies shows how to build 3D quick actions in your iOS apps

With most of the devices that Apple sell now is compatible with 3D touch it is imperative you need it in your apps. Promatics Technologies here explains how to achieve the same.

image

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 app 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.

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.

  • HomeScreenQuick Action API
  • Web view peek and pop API
  • UIKit peek and pop API
  • UITouch force properties

image

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 –

  • UIApplicataionShortCutItem Type – This is an app specific string that is used to identify quick action.
  • UIApplicataionShortCutItem Title – This string is displayed to the user. If required, it displays 2 lines as long as there is no subtitle.
  • UIApplicataionShortCutItemIcon Type – This is an optional string for system icon that displays with quick action.
  • UIApplicataionShortCutItem UserInfo - This is an optional string for icon image in app bundle or asset catalogue
  • UIApplicataionShortCutItemIcon File – This is an optional string for icon image in asset catalogue.

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 –

Init(type: String,

LocalizedTitle: String,

localizedSubtitle: String?,

icon: UIApplicationShirtCutIcon?,

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,

                localizedTitle: 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 called applicationDidBecomeActive 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.

Conclusion

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. As a top app development company, we at Promatics are looking forward to unlock the true potential of 3Dtouch development to make mobile apps more usable.

News From

Promatics TechnologiesPromatics Technologies
Category: Mobile App DevelopersCompany profile: Promatics Technologies is an ISO 9001:2008 certified mobile app development company based in India. With over 5 offices across the globe Promatics has been delivering native as well as hybrid apps for its clients since several years. Promatics has been time and again inculcated in the list of globally recognized and acclaimed app developers; by industry research firms and associations. It is no surprise as it has all this while demonstrated and showcased its ability to fabricate the most amazing ...