Skip to content

Instantly share code, notes, and snippets.

@EddyVerbruggen
Last active June 20, 2016 06:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EddyVerbruggen/99e054a6a5f4b08e5a45 to your computer and use it in GitHub Desktop.
Save EddyVerbruggen/99e054a6a5f4b08e5a45 to your computer and use it in GitHub Desktop.
NativeScript 3D Touch shortcut icons

{N} 3D Touch static icons

If you want to add static shortcut items to your app's home icon you need to add an entry to your app's .plist (this defines the icons) and (what I found easiest) to your main app.js (this is where you handle launches through those icons).

example

// Open your app's main js file and add this handler (delimited by 'START 3DTouch wiring' and 'END 3DTouch wiring').
// Then tweak the handling of 'shortcutItem.type' to your liking (here I'm deeplinking 'compose' to the 'compose' page and ignore other shortcut types).
var application = require("application");
application.cssFile = "./app.css";
application.mainModule = "main-page";
// START 3DTouch wiring
var MyDelegate = (function (_super) {
__extends(MyDelegate, _super);
function MyDelegate() {
_super.apply(this, arguments);
}
MyDelegate.prototype.applicationPerformActionForShortcutItemCompletionHandler = function (application, shortcutItem, completionHandler) {
console.log("app was launched by shortcut type '" + shortcutItem.type + "' with title '" + shortcutItem.localizedTitle + "'");
// this is where you handle any specific case for the shortcut
if (shortcutItem.type == "compose") {
// this is an example of 'deeplinking' through a shortcut
var frames = require("ui/frame");
frames.topmost().navigate("compose");
} else {
// .. any other shortcut handling
}
};
MyDelegate.ObjCProtocols = [UIApplicationDelegate];
return MyDelegate;
})(UIResponder);
application.ios.delegate = MyDelegate;
// END 3DTouch wiring
application.start();
<!-- Add this to your app's plist file, which adds two 'static' shortcut items to your app's home icon: -->
<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypePlay</string>
<key>UIApplicationShortcutItemType</key>
<string>play</string>
<key>UIApplicationShortcutItemTitle</key>
<string>Play</string>
<key>UIApplicationShortcutItemSubtitle</key>
<string>that funky music</string>
</dict>
<dict>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypeCompose</string>
<key>UIApplicationShortcutItemTitle</key>
<string>Compose</string>
<key>UIApplicationShortcutItemType</key>
<string>compose</string>
<key>UIApplicationShortcutItemSubtitle</key>
<string>write an e-mail</string>
</dict>
</array>
@EddyVerbruggen
Copy link
Author

EddyVerbruggen commented Jun 14, 2016

UPDATE: I've now created a plugin featuring 3D Touch Home Actions (static and dynamic), so you won't need to mess with this Gist anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment