Quick Action-3D touch

19 / Apr / 2016 by Nehu Gumber 0 comments

In this blog, we will be discussing about Quick Action (Another feature provided by Apple in iOS 9.0 and above)

To learn about peek and pop, you can refer my previous blog: http://www.tothenew.com/blog/playing-with-3d-touch-ios/

QUICK ACTIONS

Home screen quick actions give us a convenient way to perform useful, app-specific actions directly from the Home screen without entering inside the app.

Camera Home Screen Quick Action

Camera Home Screen Quick Action

Custom Home screen Quick Action

Custom Home screen Quick Action 

iOS9 supports, static and dynamic quick actions.

Steps for static quick action Implementation:

  1. Open info.plist in your project
  2. Open it as source code of the plist file and add below code:

<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypeSearch</string>
<key>UIApplicationShortcutItemTitle</key>
<string>SEARCH</string>
<key>UIApplicationShortcutItemType</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).Search</string>
</dict>
<dict>
<key>UIApplicationShortcutItemTitle</key>
<string>FAVORITES</string>
<key>UIApplicationShortcutItemType</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).Favorites</string>
<key>UIApplicationShortcutItemIconFile</key>
<string>ShortcutIconFavorites</string>
</dict>
</array>

The above code provides us with some keys that are needed to add quick action.

The required keys are :

  • UIApplicationShortcutItemType : A string that is sent as a part of UIApplicationShortcutItem. It can be used in code for handling different actions.
  • UIApplicationShortcutItemTitle : This is the title that will be displayed on quick action menu.

The optional keys are:

  • UIApplicationShortcutItemSubtitle: An optional key that describes the subtitle of your action displayed under the title.
  • UIApplicationShortcutItemIconType: An optional string which define built in action type

To check the list of built-in icons go through the following link:

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationShortcutIcon_Class/index.html#//apple_ref/c/tdef/UIApplicationShortcutIconType

  • UIApplicationShortcutItemIconFile — an optional string specifying an image from Assets Catalog or from the Bundle. More information on image sizes and design guidelines can be found here. If this key is specified, then the system ignores UIApplicationShortcutItemIconType;
  • UIApplicationShortcutItemUserInfo — an optional dictionary of additional information which you may want to parse.

Steps for dynamic quick action implementation:

  1. Open initial viewController and add following code in viewDidLoad():

let DeleteShortcut= UIApplicationShortcutItem(type: ” com.ttndevelopment.quickAction”, localizedTitle: “Delete item”, localizedSubtitle: “Dynamic Action”, icon: UIApplicationShortcutIcon(type: .Delete), userInfo: nil)

UIApplication.sharedApplication().shortcutItems = [DeleteShortcut]

Provide an appropriate action for them.

We should always keep in mind that there are two different situations:

  • The application is closed and the user opens the application via quick action shortcut. In this case application:didFinishLaunchingWithOptions: will be called. launchingOptions will contain UIApplicationShortcutItem stored on key UIApplicationLaunchOptionsShortcutItemKey;
  • The application was opened before and the user wants to continue usage with a shortcut. In this case the application will call this AppDelegate

func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem,completionHandler: (Bool) -> Void) {print(“Shortcut tapped”)}

 Conclusion:

  1. It gives us quick access to everything.
  2. We can enter directly to various controllers where we want to perform some or other actions.
  3. We can peek into various things directly inspite of going for its details.

 

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *