Description of the problem
Running the sample code in the documentation, when the user tries to add a contact and does not allow the app to access the Contacts, the app crashes. This is because the callback of Ti.Contacts.requestAuthorization always has e.success set to true.
Steps to reproduce
Using the code below, just click on the label and click on "Don't Allow". The app crashes.
var win = Ti.UI.createWindow({
backgroundColor : '#ffffff'
});
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 : 'John',
lastName : 'Doe',
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.open();
Note
You might add a check for Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED in the callback to avoid the issue. From the docs, is not fully clear if the callback should return e.success=true only if the user allows. The sample is the same as above.
Tested and confirmed. If you add Ti.API.info(e); after line 27 to trace the request event result, you will see success = 1, even if you click Don't Allow.
[~dcassenti] Is this only on iOS 7?
Downgrading priority.
Bug exist with TiSDK 3.2.1.GA and 3.2.0 but cannot reproduce with 3.4.0 GA Appcelerator Studio, build: 3.3.0.201407111535 iOS 7.0.3
Verified with : Appcelerator Studio:3.4.0.201409101253 Sdk:3.4.0.v20140910235714 alloy:1.5.0-rc titanium:3.4.0-rc titanium-code-processor:1.1.1 acs:1.0.16 npm:1.3.2 OS:Maverick(10.9.4) xcode: Xcode6GMSeed Device:iPhone5c(v8.0) Using the above code, clicking on the label and then clicking on "Don't Allow". App not crashes. Getting Alert as "not allowed". Working as expected. Hence closing the issue