31 January, 2017

IOS: How to enable ForceTouch support (2/2)

This is part 2 of a double post (see http://blog.clauskonrad.net/2017/01/ios-how-to-enable-force-touch-support-12.html for part 1)

Continuing from the previous post; once you have the UI defined - we need to be able to handle that the app is launched by pressing one of thUIApplicationShortcutItems instead of conventional icon click. The key to detecting this in the app is the appDelegate class (the startup class). As you might remember from part 1, we gave the shortcutItems a unique type (a unique string). These strings are used to identify to the app what shortcut item has been pressed.

As seen from the below image - the first thing when the app is launched is to check the launchOptions  argument. If it is possible to cast that as a UIApplicationShortcutItem - we have been launched from such UISchortcutItem.


The next thing is to determine which item (item1 or item 2) has been used to launch the app.


In my sample app - the startup viewcontroller as seen below is a TabbarController that normally would start the left hand child viewcontroller (Network Info) as this has index = 0 (default). Therefore I can just set the selectedIndex on the tabbarController as seen in the code above. This will allow me to either select the Network Info or Cell Info tab. All from the UIShortcutItem.






No comments:

InRiver: Not loading your extensions?

(You really need to in the loop to appreciate the issue this post addresses). Man, I've been fighting this problem for hours before I ...