Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-19473

iOS9: Ti Contact might lead to a app crash

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Release 5.0.0
    • Component/s: iOS
    • Labels:
    • Environment:

      iOS 9
      Latest SDK 5.0.0.v20150904155512
      Studio 4.1.2

    • Story Points:
      5
    • Sprint:
      2015 Sprint 18 SDK

      Description

      Reproduce

      1.Simply run the following code.

      Titanium.UI.setBackgroundColor('#000');
       
      var win1 = Titanium.UI.createWindow({  
          title:'Tab 1',
          backgroundColor:'#fff'
      });
       
      var addButton = Ti.UI.createButton({
      	title: "Add Contact",
      	top: "100",
      	left: "100"
      });
      addButton.addEventListener('click', function() {
      	addToDeviceContacts('Lorem', 'Ipsum');
      });
      win1.add(addButton);
       
      var searchButton = Ti.UI.createButton({
      	title: "Search Contact",
      	top: "300",
      	left: "100"
      });
      searchButton.addEventListener('click', function() {
      	var flag = searchPhoneBookContact('Lorem', 'Ipsum');
      	if (flag == true) {
      		alert("Contact Available");
      	} else if (flag == false) {
      		alert(" Contact Not Available");
      	}
      });
      win1.add(searchButton);
       
      win1.open();
       
      function addToDeviceContacts(firstname, lastname) {
      	if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED) {
      		addContact(firstname, lastname);
      	} else if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN) {
      		Ti.Contacts.requestAuthorization(function(e) {
      			if (e.success) {
      				addContact(firstname, lastname);
      			} else {
      				addressBookDisallowed();
      			}
      		});
      	} else {
      		addressBookDisallowed();
      	}
      };
       
      function addContact(firstname, lastname) {
      	var work_address = {
      		
      	};
      	work_address.Street = 'street';
      	work_address.City = 'workAddress';
      	work_address.Country = 'country';
       
      	var tempMobile = '9999988888';
      	var tempPhone = '000000000';
      	var tempEmail = 'test@gmail.com';
       
      	var contact = Titanium.Contacts.createPerson({
      		firstName : (firstname != undefined) ? (firstname) : 'FirstName',
      		lastName : (lastname != undefined) ? (lastname) : 'LastName',
      		email : {
      			work : [tempEmail]
      		},
      		address : {
      			work : [work_address]
      		},
      		phone : {
      			mobile : [tempMobile],
      			"main" : [tempPhone]
      		},
      		note : 'Saved from app'
      	});
      	
      	alert('Contact saved');
      }
       
      function searchPhoneBookContact(firstname, lastname) {
      	if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED) {
      		var flag = performSearchFunction(firstname, lastname);
      		return flag;
      	} else if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN) {
      		Ti.Contacts.requestAuthorization(function(e) {
      			if (e.success) {
      				var flag = performSearchFunction(firstname, lastname);
      				return flag;
      			} else {
      				Ti.API.info("address book disallowed");
      			}
      		});
      	} else {
      		Ti.API.info("address book disallowed");
      	}
      }
       
      function performSearchFunction(firstname, lastname) {
      	Ti.API.info("Address book Allowed");
      	if (Ti.Contacts.getPeopleWithName(firstname + ' ' + lastname).length > 0) {
      		return true;
      	} else {
      		return false;
      	}
      };
       
      function addressBookDisallowed() {
      	alert('Phone book can not be accessed from this app!! Access denied');
      }
      

      2.Click the add button to add a new contact
      3.Click the search button.

      Result:

      App will crash.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                cng Chee Kiat Ng (Inactive)
                Reporter:
                sliang Shuo Liang
                Reviewer:
                Hans Knöchel
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-20330
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration