15 March 2016
Basic familiarity with building mobile apps on Adobe AIR, including familiarity with Adobe Native Extensions.
Required third-party products
All
With iPhone 6s and 6s Plus, Apple has introduced a new feature called 3D Touch, which is available on iOS 9.0 and higher. With 3D Touch, an iPhone app can now sense how much pressure a user is exerting on the device screen and accordingly respond to the different pressure levels.
3D Touch Native Extension allows an ActionScript developer to access 3D Touch APIs from the AIR app. This native extension provides the following features:
The ActionScript contains touch3D class. This class provides the following public methods to the AIR application:
public function addShortcutItem(shortcutItemType:String="",shortcutItemTitle:String=" ", shortcutItemSubtitle:String="",shortcutItemIconType:String=""):voidpublic function enableForceTouch():voidpublic function isSupported():Booleanpublic function init():voidThe ActionScript developers need to use these methods to have the 3D Touch feature in their AIR apps. The AIR application can create many instances of the touch3D class. However, the touch3D class creates only one instance of the ExtensionContext class instance, that all the instances share.
To use the 3D Touch Air Native Extension, an AIR application does the following:
var touch:Touch3D = new Touch3D();
if(touch.isSupported())
{
touch.init();
touch.addEventListener(Touch3DEvent.SHORTCUT_ITEM,itemStatus);
touch.addEventListener(Touch3DEvent.PRESSURE,pressureStatus);
touch.addShortcutItem("com.shortcutMail","Send Mail","For Sending Mails","UIApplicationShortcutIconTypeMail");
touch.addShortcutItem("com.shortcutProhibit","Prohibit Item","Show Prohibited Screen","UIApplicationShortcutIconTypeProhibit");
touch.enableForceTouch();
}
The example given above uses all the methods that are available in touch3D class. These methods are explained below.


touch.removeShortcutItem("com.shortcutProhibit");touch.addEventListener(Touch3DEvent.PRESSURE,pressureStatus). You also need to write a response for the pressureStatus method call:protected function pressureStatus (event: Touch3DEvent):void
{
var pressureValue:String = "Pressure Value: "+event.itemType+" "+event.itemValue;
}
The images below show Force Percentage values 46.00 and 100.00 applied by the user on the app screen.


touch.addEventListener(Touch3DEvent.SHORTCUT_ITEM,itemStatus);Next, you need to write the response for the itemStatus method call. Add the following function:
protected function itemStatus(event:Touch3DEvent):void
{
textTitle.text = event.itemType;
textLabel.text = "Launched through shortcut item, "+ event.itemValue;
}
touch.addEventListener(Touch3DEvent.PRESSURE,pressureStatus);Next, you need to write the response for the pressureStatus method call. Add the following function:
protected function pressureStatus(event:Touch3DEvent):void
{
textTitle.text = event.itemType;
textLabel.text = "Pressure value is: "+ event.itemValue;
}
3D Touch ANE also supports static shortcut items, which can be added directly to the app descriptor. So, apart from using the dynamic method through addShortcutItem(), developers can also choose the static method to add the shortcut items. Users can see the static items before the first launch of the app, whereas dynamic items will be available only after the first launch.
A maximum of four shortcuts are supported by iOS. As such, if you use two static shortcuts in your descriptor, you can only add two additional dynamic shortcuts to the app.
Example: How to add static shortcut items in app descriptor?
<iPhone>
<InfoAdditions><![CDATA[
<key>UIDeviceFamily</key>
<array>
<string>1</string>
<string>2</string>
</array>
<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemIconFile</key>
<string>open-favorites</string>
<key>UIApplicationShortcutItemTitle</key>
<string>No Icon Screen</string>
<key>UIApplicationShortcutItemType</key>
<string>com.shortcut</string>
<key>UIApplicationShortcutItemUserInfo</key>
<dict>
<key>key1</key>
<string>value1</string>
</dict>
</dict>
<dict>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypeCompose</string>
<key>UIApplicationShortcutItemTitle</key>
<string>Compose Mail</string>
<key>UIApplicationShortcutItemType</key>
<string>com.shortcutCompose</string>
<key>UIApplicationShortcutItemUserInfo</key>
<dict>
<key>key2</key>
<string>value2</string>
</dict>
</dict>
</array>
]]></InfoAdditions>
<requestedDisplayResolution>high</requestedDisplayResolution>
</iPhone>
The iOS native library is implemented in Objective C, using the native extension C API. The native library include the following methods:
UIMutableApplicationShortcutItem object.For more information about developing native extensions for Adobe AIR, see:
For more information about using a native extension in an AIR application, see: