3D touch on the iPhone 6s

On the new iPhone 6s, Apple have added a cool new feature called 3d touch. This enables users to press harder on an object and get a contextual menu of different options. I think this is a pretty cool feature and look forward to adding it to the DoneDeal iOS app in the coming weeks. There are two features that I can see being useful in the DoneDeal app.

Quick actions and Peek and Pop. Quick actions allow you to add some actions to the home screen.

These are pretty easy to add to an application, you first add some actions to display in the application’s Info.plist file and then you can handle these quick actions in the applications AppDelegate file. I set up a sample project to try out some of these new features. This project can be found on my Github account. Unfortunately there is no easy way to test this out on a simulator so it has to be running on a device supporting 3d touch to work. Setting up your quick actions in Info.plist First define an array called UIApplicationShortcutItems. This can have up to 4 items. Each shortcut item has two mandatory field and 3 other optional fields. Mandatory Fields

UIApplicationShortcutItemTitle (This is the title text that is displayed on a Quick Action)

UIApplicationShortcutItemType = (This is a unique identifier that will be used in the AppDelegate to determine which Quick Action was tapped) Optional Fields

UIApplicationShortcutItemSubtitle = (This is a subtitle text that will is displayed on a Quick Action)

UIApplicationShortcutItemIconType = (This is an icon that can be displayed on a Quick Action)

UIApplicationShortcutItemUserInfo = (This is a dictionary containing any extra information that you wish to pass to your AppDelegate) The above is all that is needed to get your quick actions to display. Handling UIApplicationShortcuts in AppDelegate To handle the shortcuts we must implement application:performActionForShortcutItem:completionHandler Here we can access UIApplicationShortcutItem.type to check which shortcut was tapped. We need to handle a case where the application was already active when the shortcut item was tapped. If the app was already active, then applicationDidFinishLaunchingWithOptions would not be called. Here we put the code to handle the shortcut in applicationDidBecomeActive. Peek and Pop Apple have also added a new feature donned Peek and Pop. This allows you to get a preview of a view controller before opening it. To enable this your ViewController must first subscribe to UIViewControllerPreviewingDelegate. In viewDidLoad you must call the registerForPreviewingWithDelegate method. Next we implement the UIViewControllerPreviewingDelegate functions to handle the 3d touch events on the UITableViewCells. Once the above functions have been implemented, it will be possible to 3d touch a UITableViewCell and see a preview of the view controller that it would segue to. Here is a video of the sample project. As can be seen it is pretty simple and easy to add these new features and after using them for a while it becomes second nature.