Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15391] iOS: Ti.Contacts.requestAuthorization always returns e.success=true in the callback, even if the users doesn't allow

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2014-09-04T06:21:15.000+0000
Affected Version/sRelease 3.1.3, Release 3.2.1
Fix Version/sRelease 3.4.0
ComponentsiOS
Labelsqe-closed-3.4.0, supportTeam
ReporterDavide Cassenti
AssigneeIngo Muschenetz
Created2013-10-03T11:00:57.000+0000
Updated2014-09-11T11:02:06.000+0000

Description

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.

Comments

  1. kosso 2013-10-07

    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.
  2. Ingo Muschenetz 2013-10-07

    [~dcassenti] Is this only on iOS 7?
  3. Ingo Muschenetz 2013-10-08

    Downgrading priority.
  4. Shameer Jan 2014-09-04

    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
  5. Priya Agarwal 2014-09-11

    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

JSON Source