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).
Last active
June 20, 2016 06:20
-
-
Save EddyVerbruggen/99e054a6a5f4b08e5a45 to your computer and use it in GitHub Desktop.
NativeScript 3D Touch shortcut icons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.