[TIMOB-11174] iOS 6: Ti.Contacts-Module broken
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Critical |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2012-10-06T02:46:21.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 2.1.3, Release 3.0.0, Sprint 2012-20 API, 2012 Sprint 20 |
| Components | iOS |
| Labels | api, contacts, device, ios, ios6, iphone, qe-ios6, qe-port |
| Reporter | Hans Knöchel |
| Assignee | Blain Hamon |
| Created | 2012-09-25T16:34:44.000+0000 |
| Updated | 2012-10-06T02:46:21.000+0000 |
Description
The method "getAllContacts()" of the Ti.Contacts is broken when installing the app on a device (tested with Ti-SDK 2.1.3 GM, iOS 6 and iPhone 5). It works great in the simulator but not on the given device.
*Code-Example:*
var data = [];
var contacts = Titanium.Contacts.getAllPeople();
for (var i = 0; i < contacts.length; i++) {
data.push({
name : contacts[i].firstName,
surname : contacts[i].lastName,
phone : contacts[i].phone
});
}
Ti.API.info("Collected Contacts: \n"+data);
What is the behavior you see on device? Is there just no data?
Yes, there is just returned an empty array (data). Note: After i used Ti.Contacts.showContacts(), granted the permission for the contacts and then tried it again, the data was given. So it's obviously a bug where we need to ask for permissions to access the contacts (like in the Geolocation-API).
Able to reproduce the issue on SDK : 2.1.3.v20120921190208 & Iphone 5- iOS6. It does not ask for any permissions to access contacts & we get a empty array. Also,building with iOS SDK 5.1 & titanium SDK 2.1.2 GA asks us for the permission to access the contacts. Running in simulator for iOS SDK 5.1 & titanium SDK 2.1.2 GA returns us "Collected Contacts : [objects,objects],...."
Expanded test case
var win = Ti.UI.createWindow({backgroundColor:'gray'}); var label = Ti.UI.createLabel({ text:'Check log for contacts details.', width:Ti.UI.SIZE, height:Ti.UI.SIZE, }); win.add(label); var performAddressBookFunction = function(){ var data = []; var contacts = Titanium.Contacts.getAllPeople(); Ti.API.info("Collected Contacts: data length : "+ data.length); for (var i = 0; i < contacts.length; i++) { data.push({ name : contacts[i].firstName, surname : contacts[i].lastName, phone : contacts[i].phone }); Ti.API.info(" \n"+data[i].name + ' ' + data[i].surname); } }; var addressBookDisallowed = function(){ Titanium.UI.createAlertDialog({ title:'CONTACTS ACCESS DENIED', message:'Your app does not have access to the Contacts database. Please check privacy settings.' }).show(); }; 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 { label.text= 'contacts not available.'; addressBookDisallowed(); } }); } else { addressBookDisallowed(); } win.open();Master PR https://github.com/appcelerator/titanium_mobile/pull/3078 2_1_X PR https://github.com/appcelerator/titanium_mobile/pull/3084
Verified fix with: Titanium Studio, build: 2.1.2.201208301612 Titanium SDK: 3.0.0.v20120929141713 Titanium SDK: 2.1.3.v20120928203111 Devices: iPhone4 ios5.1.1 iPhone5 ios 6.0 Closing the bug.
Reopened to adjust remaining estimate.