-
-
Save hansemannn/ae779a3287640e1d0b3b to your computer and use it in GitHub Desktop.
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
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