Guest User

Untitled

a guest
Dec 17th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. var win = Ti.UI.createWindow({
  2.  
  3. });
  4.  
  5. var lbl = Ti.UI.createLabel({
  6. text : "click to add a contact"
  7. });
  8. win.add(lbl);
  9.  
  10. lbl.addEventListener(
  11. 'click',
  12. function(e) {
  13. var performAddressBookFunction = function() {
  14. Ti.Contacts.createPerson({
  15. firstName : 'ABC',
  16. lastName : 'DEF',
  17. organization : 'Appcelerator',
  18. phone : {
  19. mobile : [ '07900 000001', '07900 000002' ]
  20. }
  21. });
  22. };
  23. var addressBookDisallowed = function() {
  24. alert("not allowed");
  25. };
  26. if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED) {
  27. performAddressBookFunction();
  28. } else if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN) {
  29. Ti.Contacts.requestAuthorization(function(e) {
  30. if (e.success) {
  31. performAddressBookFunction();
  32. } else {
  33. addressBookDisallowed();
  34. }
  35. });
  36. } else {
  37. addressBookDisallowed();
  38. }
  39. });
  40.  
  41. win.addEventListener("open", function(e) {
  42.  
  43. const contactsPermissions = [ 'android.permission.READ_CONTACTS',
  44. 'android.permission.WRITE_CONTACTS' ];
  45. Ti.Android.requestPermissions(contactsPermissions, function(e) {
  46. if (e.success) {
  47. Ti.API.info('SUCCESS');
  48. } else {
  49. Ti.API.info('ERROR: ' + e.error);
  50. }
  51. });
  52.  
  53. /*
  54. * if (Ti.Contacts.hasContactsPermissions()) { Ti.API.info("People: " +
  55. * JSON.stringify(Ti.Contacts.getAllPeople())); } else {
  56. * Ti.Contacts.requestContactsPermissions(function(e) { if (e.success ===
  57. * true) { alert("Access granted"); Ti.API.info("People: " +
  58. * JSON.stringify(Ti.Contacts.getAllPeople())); } else { alert("Access
  59. * denied, error: " + e.error); } }); }
  60. */
  61. });
  62.  
  63. win.open();
Add Comment
Please, Sign In to add comment