Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
Last active March 15, 2017 14:20
Show Gist options
  • Save benbahrenburg/905e349da733dcfaf164 to your computer and use it in GitHub Desktop.
Save benbahrenburg/905e349da733dcfaf164 to your computer and use it in GitHub Desktop.
example of app shortcuts
Ti.App.addEventListener("resume", function(){
Ti.API.info("Resume Event Fired");
});
Ti.App.addEventListener("resumed", function(){
Ti.API.info("Resumed Event Fired");
});
Ti.App.iOS.addEventListener("shortcutitemclick", function(e){
Ti.API.info("shortcutitemclick Event Fired");
Ti.API.info("event payload:" + JSON.stringify(e));
});
var win = Titanium.UI.createWindow({
title:'Test', backgroundColor:'#fff', layout:"vertical"
});
var btn1 = Ti.UI.createButton({
top: 50, height:45, title:"Add Contact Us Application Shortcut"
});
win.add(btn1);
btn1.addEventListener("click",function(){
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts();
appShortcuts.addShortcutItem({
type:"contact_us",
title:"Contact Us",
subtitle:"Tap to reach us",
icon: Ti.UI.iOS.SHORTCUT_ICON_TYPE_ADD,
userInfo:{
infoKey:"contact_us"
}
});
});
var btn2 = Ti.UI.createButton({
top: 10, height:45, title:"Remove Contact Us Application Shortcut"
});
win.add(btn2);
btn2.addEventListener("click",function(){
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts();
appShortcuts.removeShortcutItem({
type:"contact_us"
});
});
var btn3 = Ti.UI.createButton({
top: 10, height:45, title:"Count Dynamic App Shortcuts"
});
win.add(btn3);
btn3.addEventListener("click",function(){
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts();
var shortcutItems = appShortcuts.listDynamicShortcuts();
Ti.API.info("Dynamic App Shortcut count:" + shortcutItems.length);
Ti.API.info("Dynamic App Shortcut as JSON:" + JSON.stringify(shortcutItems));
});
var btn4 = Ti.UI.createButton({
top: 10, height:45, title:"Count Static App Shortcuts"
});
win.add(btn4);
btn4.addEventListener("click",function(){
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts();
var shortcutItems = appShortcuts.listStaticShortcuts();
Ti.API.info("Static App Shortcut count:" + shortcutItems.length);
Ti.API.info("Static App Shortcut as JSON:" + JSON.stringify(shortcutItems));
});
var btn5 = Ti.UI.createButton({
top: 10, height:45, title:"Dynamic Shortcut Exists?"
});
win.add(btn5);
btn5.addEventListener("click",function(){
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts();
var exists = appShortcuts.dynamicShortcutExists({
type:"contact_us"
});
var msg = (exists) ? "Icon exists" : "Sorry isn't there";
alert(msg);
});
var btn6 = Ti.UI.createButton({
top: 10, height:45, title:"Remove All Dynamic Shortcuts"
});
win.add(btn6);
btn6.addEventListener("click",function(){
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts();
appShortcuts.removeAllDynamicShortcuts();
});
win.open();
@aakashsharmaindore
Copy link

i got errro in this code when i am using ApplicationShortcuts.

TypeError: undefined is not a function (evaluating 'appShortcuts.addShortcutItem')

Anyone?????

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