Code Monkey home page Code Monkey logo

rs3dtouch's Introduction

How to Implement 3D touch to use Application shortcut Items in iOS devices

Apple developer documentation: https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/Adopting3DTouchOniPhone/

Inspired from: https://developer.apple.com/library/content/samplecode/ApplicationShortcuts/Introduction/Intro.html#//apple_ref/doc/uid/TP40016545-Intro-DontLinkElementID_2

Follow step by step guide to learn about how to create/use the shortcut items (quick actions) for your application in iOS device.

Background:

Quick actions (application shortcuts) can be used by deep 3D press on the app icon at iOS device home screen. This will apply to devices which supports 3D touch (not all iOS device). There are two types of quick actions

  • Static quick actions - We can add them in info.list

  • Dynamic quick actions - we can add it via runtime through code.

Static Quick Actions:

In this step we will learn how to add static actions in your application.
  • First select info.plist file in your app.

  • At the last entry of the item in info.plist you can see "+" add button click on it

  • It will create a new row and ask for key and enter "UIApplicationShortcutItems"

  • Now, it is the type of array as we can include more than one shortcut items so select array as type .

image alt text

  • Now click on the expand arrow on left side of item and click on "+" add button and select type as dictionary. Here we are creating dictionary because we can store multiple key-value pair as an object of array.

  • Click on the arrow to the left of the Item0 key so that it is pointing downward and click on the + button to add the first entry into the dictionary.

image alt text

  • Now here use can add the information you required to show for the item.

  • There are five keys right now available.

  • You can see subtitle, shortcut Icon and user info are optionals.

  • At the end you will see something like this

image alt text

Dynamic Quick Actions

In next step we will learn how to add dynamic actions in your application.
  • To add dynamic quick actions we need to implement it.

  • We can add a method in the AppDelegate.swift to add those actions.

  • These items are using the mutable class "UIMutableApplicationShortcutItem"

  • Once you created the items you can use the shortcutItems array of application context.

  • To add dynamic quick action you can create a method and call it from AppDelegate.swift file and modify the didFinishLaunchingWithOptions method.

image alt text

  • You won’t see these item before launching the app one time because the code needs to execute before it shows output. So please allow application to run at least one time and then you can see all options like below image.

image alt text

  • You can see total 4 items one we have added through static quick actions and other three from dynamic quick actions.

Edit Quick Actions

  • If you want to remove all items you can just simply do this.

image alt text

  • If you want to update one of the item you can just replace the item in the array shortcutItems.

image alt text

Responding to Quick Actions

  • When you select any item from menu it will call appDelegate method performActionFor shortcutItem: and passed item "UIApplicationShortcutItem"

  • As we are getting ShortCutItem object we can access the properties of the object.

  • You can see example below.

image alt text

image alt text

Test Quick Actions

  • As, I mentioned earlier to use the dynamic items you have to run app at least one time and you can see all the available options by pressing 3D touch on the app icon on Home screen.

'Summary'

If you have any questions, concerned please don’t hesitate to contact me.

Twitter: @imrvshah

rs3dtouch's People

Contributors

imrvshah avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

kanakaraju043

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.