Adopting 3D Force Touch on iPhone – iOS9 Feature (Part 1)

Apple announced 3D Touch – Force Touch in the Special Event at September this year. This feature is added to iPhone6S, iPhone6S which are introduced at same event, and I think 3D Touch will be added the next generation iPhones. If you’re reading this post, you are already aware of it. 🙂

As the new iPhones have the third dimension to the user interface, now you can add quick actions and peek and pop feature to your application with this brand new cool feature easily. Sooo, where to start for basically saying that my app will use force touch for home screen?

Home Screen Quick Actions are two types: dynamic and static quick actions.

As a first thing, you should add the quick-actions definitions in the application’s Info.plist in the UIApplicationShortcutItems array. Each UIApplicationShortcutItem refers a quick action and it can and must contain some properties such as UIApplicationShortcutItemIconFile, UIApplicationShortcutItemTitle,  UIApplicationShortcutItemType,  UIApplicationShortcutItemUserInfo. Quick actions display up to two lines of text with an optional icon.You can see the all keys and their descriptions in here, Apple’s Guide.

As a brief example for define shortcutItems in Info plist:

Screen Shot 2015-11-15 at 10.45.05

Source Code:

     <key>UIApplicationShortcutItems</key>
     <array>
        <dict>
            <key>UIApplicationShortcutItemIconFile</key>
            <string>open-favorites</string>
            <key>UIApplicationShortcutItemTitle</key>
            <string>Favorites</string>
           <key>UIApplicationShortcutItemType</key>
           <string>com.mycompany.myforcetouchapp.openfavorites</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.mycompany.myforcetouchapp.newmessage</string>
           <key>UIApplicationShortcutItemUserInfo</key>
           <dict>
               <key>key2</key>
               <string>value2</string>
           </dict>
       </dict>
   </array>

When a users tap on one of your Home Screen actions, the system launches the  application: performActionForShortcutItem: completionHandler: method in app delegate of your application.

– (void)application:(UIApplication *)application
performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem
  completionHandler:(void (^)(BOOL succeeded))completionHandler

One important point! System call a launch method before this method, application: willFinishLaunchingWithOptions: or  application: didFinishLaunchingWithOptions:, if you want to configure your launch view or service calls case by case, you should handle by checking UIApplicationLaunchOptionsShortcutItemKey and reading UIApplicationShortcutItem object in this launch methods.

AS FINAL NOTES,

  • Home screen quick actions are to ensure high-value tasks, to enable quick navigation through your app, don’t use so many dynamic actions, it will be a confusion for your users to predict.
  • If you will design quick action icons, you should check this guide for simple template icons.
  • With Xcode 7.1 you must develop on a device that supports 3D Touch. Simulator in Xcode 7.1 does not support 3D Touch.

thumb_IMG_0006_1024The other question can be “Can I localize my home screen shortcut items?” especially if your app is localized and use more than one language.  Answer is YES! Check out this post about localization for Info.plist.

Peek and Pop feature integration will be the topic of next post about 3D Touch!

Also you can read another related post about implementing dynamic application short items for homescreen quick actions.

May the Force (3D Touch ) be with you!

le-me-one-fine-day-946

Advertisements

One thought on “Adopting 3D Force Touch on iPhone – iOS9 Feature (Part 1)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s