Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var win = Ti.UI.createWindow({
- });
- var lbl = Ti.UI.createLabel({
- text : "click to add a contact"
- });
- win.add(lbl);
- lbl.addEventListener(
- 'click',
- function(e) {
- var performAddressBookFunction = function() {
- Ti.Contacts.createPerson({
- firstName : 'ABC',
- lastName : 'DEF',
- organization : 'Appcelerator',
- phone : {
- mobile : [ '07900 000001', '07900 000002' ]
- }
- });
- };
- var addressBookDisallowed = function() {
- alert("not allowed");
- };
- if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED) {
- performAddressBookFunction();
- } else if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN) {
- Ti.Contacts.requestAuthorization(function(e) {
- if (e.success) {
- performAddressBookFunction();
- } else {
- addressBookDisallowed();
- }
- });
- } else {
- addressBookDisallowed();
- }
- });
- win.addEventListener("open", function(e) {
- const contactsPermissions = [ 'android.permission.READ_CONTACTS',
- 'android.permission.WRITE_CONTACTS' ];
- Ti.Android.requestPermissions(contactsPermissions, function(e) {
- if (e.success) {
- Ti.API.info('SUCCESS');
- } else {
- Ti.API.info('ERROR: ' + e.error);
- }
- });
- /*
- * if (Ti.Contacts.hasContactsPermissions()) { Ti.API.info("People: " +
- * JSON.stringify(Ti.Contacts.getAllPeople())); } else {
- * Ti.Contacts.requestContactsPermissions(function(e) { if (e.success ===
- * true) { alert("Access granted"); Ti.API.info("People: " +
- * JSON.stringify(Ti.Contacts.getAllPeople())); } else { alert("Access
- * denied, error: " + e.error); } }); }
- */
- });
- win.open();
Add Comment
Please, Sign In to add comment