×

kostenlose Beratung

Vereinbaren Sie einen Rückruf:

This field is required

Lernen Sie uns kennen
Bitte bestätigen Sie, dass Sie kein Bot sind

Oder rufen Sie uns unverbindlich an:

+49 6151 - 629 095 0

Montag - Freitag, 9:00 - 18:00 Uhr

Oder schreiben Sie uns eine Email:



Kontaktformular

This field is required


Bitte bestätigen Sie, dass Sie kein Bot sind

How to: Implementing an easy navigation for iOS with 3D Touch


With the iPhone 6s and above, Apple introduced an entirely new way of interacting with our devices called 3D Touch. 3D Touch works by detecting the amount of pressure that you are applying to your phone's screen in order to perform different actions.

One of three 3D Touch features is called Home Screen Quick Actions and this blog article will teach you how to make such thing and how to use it.

Home Screen Quick Actions

Home screen quick actions are a convenient way to perform useful, app-specific actions right from the Home screen, using 3D Touch. Apply a little pressure to an app icon with your finger—more than you use for tap and hold—to see a list of available quick actions. Tap one to activate it.

Lets start with the implementation.

With 3D Touch you can add up to four shortcuts for specific functions of your application on your app icon.

There are two main types of quick actions you can create for your app, static and dynamic.

1. Static

Static quick actions are defined in your app's Info.plist and are available at all times for your application.

Info.plist example *:

	<key>UIApplicationShortcutItems</key>
	<array>
		<dict>
			<key>UIApplicationShortcutItemIconFile</key>
			<string>UIApplicationShortcutIconTypeContact</string>
			<key>UIApplicationShortcutItemTitle</key>
			<string>Contacts</string>
			<key>UIApplicationShortcutItemType</key>
			<string>com.uhp.3DTouch.contact</string>
			<key>UIApplicationShortcutItemUserInfo</key>
			<dict>
				<key>key1</key>
				<string>value1</string>
			</dict>
		</dict>
		<dict>
			<key>UIApplicationShortcutItemIconType</key>
			<string>UIApplicationShortcutIconTypeCompose</string>
			<key>UIApplicationShortcutItemTitle</key>
			<string>New Message</string>
			<key>UIApplicationShortcutItemType</key>
			<string>com.uhp.3DTouch.newmessage</string>
			<key>UIApplicationShortcutItemUserInfo</key>
			<dict>
				<key>key2</key>
				<string>value2</string>
			</dict>
		</dict>
	</array>

* Keys that can be included in each dictionary of the array

Key Description

UIApplicationShortcutItemType (required)

A required string delivered to your app when the user invokes the corresponding quick action. Your app can use this string to classify quick actions into types, and then to disambiguate among action types it receives. You don’t need to register your quick action types.

UIApplicationShortcutItemTitle (required)

A string displayed to the user on the Home screen as the name of the quick action.

If the title fits on one line, the system displays it as a single line quick action item. If the title is too long for one line and you have not specified a UIApplicationShortcutItemSubtitle string, the system displays the title on two lines.

You can, optionally, internationalize a quick action title by employing your app’s InfoPlist.strings file. For guidance on how to do this, read Localizing Property List Values.

UIApplicationShortcutItemSubtitle

An optional string that is displayed to the user on the Home screen, immediately below the corresponding title string.

If you specify a subtitle for a quick action, the system displays the quick action title on a single line (perhaps just a portion of the title, followed by ellipsis character), no matter how long the title is.

You can, optionally, internationalize a quick action subtitle by employing your app’s InfoPlist.strings file. For guidance on how to do this, read Localizing Property List Values.

UIApplicationShortcutItemIconType

An optional string specifying the type of an icon from the system-provided library; see the UIApplicationShortcutIconType enumeration in UIApplicationShortcutIcon Class Reference. The icon is displayed in the set of quick actions for your app, along with the quick action's title, on the Home screen.

UIApplicationShortcutItemIconFile

An optional string specifying an icon image to use from the app’s bundle, or the name of an image in an asset catalog. The icon is displayed before quick action title on the Home screen.

Icons should be square, single color, and 35x35 points, as shown in these template files and as described in iOS Human Interface Guidelines.

If you specify this key, the system ignores the UIApplicationShortcutItemIconType key.

UIApplicationShortcutItemUserInfo

An optional, app-defined dictionary. One use for this dictionary is to provide app version information, as described in the “App Launch and App Update Considerations for Quick Actions” section of the overview in UIApplicationShortcutItem Class Reference.

 

2. Dynamic

 Dynamic quick actions are created in your code and are added to the shared UIApplication object for your app.

	func createQuickActions() {
        // create custom icon
        let icon1 = UIApplicationShortcutIcon.init(templateImageName: "contacts-custom-icon")
        // create deafult icon
        let icon2 = UIApplicationShortcutIcon.init(type: .compose)
        
        // create dynamic shortcut items
        let item1 = UIMutableApplicationShortcutItem.init(type: "com.uhp.3DTouch.contact", 
localizedTitle: "Contacts", localizedSubtitle: nil, icon: icon1, userInfo: nil)
        let item2 = UIMutableApplicationShortcutItem.init(type: "com.uhp.3DTouch.newmessage", 
localizedTitle: "New Message", localizedSubtitle: nil, icon: icon2, userInfo: nil)
        
        let items = [item1, item2] as Array
        let existingItems: Array = UIApplication.shared.shortcutItems! as Array
        let updatedItems: Array = existingItems + items
        UIApplication.shared.shortcutItems = updatedItems
    }

This block of code needs to be called from didFinishLaunchingWithOptions method.

Result of both types is the same:

 

Lastly we need to handle the short cut and deep link the user into the proper view controller within our app.

	func application(_ application: UIApplication, 
performActionFor shortcutItem: UIApplicationShortcutItem, 
completionHandler: @escaping (Bool) -> Void) {
        if let shortcutItemType = shortcutItem.type as String? {
            // ... do some logic here
            completionHandler(true)
        }
        
        completionHandler(false)
    }

Keep in mind that both types, static and dynamic are pretty much the same but from our perspective, we suggest using dynamic because you can use localization and add/remove list item based on application state.
 

Source:
https://developer.apple.com/design/human-interface-guidelines/ios/extensions/home-screen-actions/
https://developer.apple.com/ios/3d-touch/
https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW36
http://www.brianjcoleman.com/tutorial-3d-touch-quick-actions-in-swift/

 

Weitere Artikel

Augmented Reality: Apple bringt neue Funktionen mit iOS12 und ARKit 2


[Read more]

Vom ambitionierten Team zum stabilen Partner mit 35 Mitarbeitern


[Read more]

How to: Implementing an easy navigation for iOS with 3D Touch


[Read more]

Antworten auf diesen Post


 von  {{comment.name}}  am  {{comment.date | date:'dd.MM.yyyy, HH:mm'}}

{{comment.comment}}


Kommentar hinzufügen


Bitte geben Sie Ihre E-Mail Adresse an Ungültige E-Mail Adresse
Bitte geben Sie Ihren Namen an
Bitte geben Sie Ihren Kommentartext ein

This field is required


Bitte bestätige, dass du kein Bot bist
Vielen Dank für Ihren Kommentar

Lernen Sie uns kennen

Dominik Unzicker

Starten wir gemeinsam in Ihre digitale Zukunft.
Wir freuen uns auf Ihre Anfrage.


 

This field is required


Bitte bestätigen Sie, dass Sie kein Bot sind