Skip to content

Instantly share code, notes, and snippets.

@hansemannn
Created October 13, 2015 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hansemannn/ae779a3287640e1d0b3b to your computer and use it in GitHub Desktop.
Save hansemannn/ae779a3287640e1d0b3b to your computer and use it in GitHub Desktop.
Ti.App.iOS.addEventListener("shortcutitemclick", function(e){
Ti.API.info("shortcutitemclick Event Fired");
Ti.API.info("person:" + JSON.stringify(e.userInfo.person));
});
var win = Titanium.UI.createWindow({
title:'Test', backgroundColor:'#fff', layout:"vertical"
});
var btn1 = Ti.UI.createButton({
top: 50, height:45, title:"Add Ti.Contacts Application Shortcut"
});
win.add(btn1);
btn1.addEventListener("click",function(){
if(!Ti.Contacts.hasContactsPermissions()) {
Ti.Contacts.requestContactsPermissions(function(e) {
if(e.success) {
createShortcut();
}
})
} else {
createShortcut();
}
});
var btn2 = Ti.UI.createButton({
top: 10, height:45, title:"Remove Ti.Contacts Application Shortcut"
});
win.add(btn2);
btn2.addEventListener("click",function(){
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts();
appShortcuts.removeDynamicShortcut("contact_us");
});
function createShortcut() {
Ti.Contacts.showContacts({
selectedPerson: function(e) {
var person = e.person;
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts();
appShortcuts.addDynamicShortcut({
itemtype:"contact_us",
title: person.fullName,
subtitle: "Tap to call",
icon: person,
userInfo: {
person: {
firstName: person.firstName,
lastName: person.lastName
}
}
});
}
});
}
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment