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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: Release 3.1.3, Release 3.2.1
    • Fix Version/s: Release 3.4.0
    • Component/s: iOS
    • Environment:

      SDK 3.1.3, 3.2.1.GA

      TI CLI 3.2.1

      iOS 7

      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.

        Attachments

          Activity

            People

            • Assignee:
              ingo Ingo Muschenetz
              Reporter:
              dcassenti Davide Cassenti
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

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

                  Git Integration