locked
WTF? Now adding removing contacts from the ContactPickerUI crashes the app with access denied?

    Question

  • HEllo guys.

    I must say that I'm pretty pissed about this!

    A long time ago I've asked for a change in the ContactPickerUI API. AS I've complained at the time, there was no way for me to get the current selection mode during the current operation. Notice that the selection mode I'm referring is knowing if my app is being used to allow the choice of a single contact or multiple contacts and not that fields vs contact setting thingy you can get from ContactPickerUI's selectionMode property!

    Without this property, I had to resort to a workaround. The idea is to add two items and see if they're both at the collection. this wasn't great because the user was able to see a flash at the bottom of the screen, but it was a good way for me to see if my dialog was supposed to allow the selection of one or more contacts. here's the function I was using:

    function verificaSePermiteVarios() {
        var aux = [
            {
                id: contactos[0],
                ct: criaContactoParaBasket(contactos[0])
            },
            {
                id: contactos[1],
                ct: criaContactoParaBasket(contactos[1])
            }
        ];

            contactPickerUI.addContact(aux[0].id, aux[0].ct);
            contactPickerUI.addContact(aux[1].id, aux[1].ct);
            setTimeout(function () {
                var permiteVarios = contactPickerUI.containsContact(aux[0].id) &&
                contactPickerUI.containsContact(aux[1].id);
                lista.selectionMode = permiteVarios ? "multi" : "single";
                //limpar items
                contactPickerUI.removeContact(aux[0].id);
                contactPickerUI.removeContact(aux[1].id);
                verificouSelecao = true;
        },
        500);
    }

    NOw, I've just noticed that I started getting access denied at the addContact method. Since this call was being called from activated event, I've noticed that now I need to increase the time and use two timeouts methods!

           

    function verificaSePermiteVarios() {
        var aux = [
            {
                id: contactos[0],
                ct: criaContactoParaBasket(contactos[0])
            },
            {
                id: contactos[1],
                ct: criaContactoParaBasket(contactos[1])
            }
        ];

        setTimeout(function () {
            contactPickerUI.addContact(aux[0].id, aux[0].ct);
            contactPickerUI.addContact(aux[1].id, aux[1].ct);
            setTimeout(function () {
                var permiteVarios = contactPickerUI.containsContact(aux[0].id) &&
                contactPickerUI.containsContact(aux[1].id);
                lista.selectionMode = permiteVarios ? "multi" : "single";
                //limpar items
                contactPickerUI.removeContact(aux[0].id);
                contactPickerUI.removeContact(aux[1].id);
                verificouSelecao = true;;
            },
            1000);

        },
        1000);
    }

    Now, this is a HUGE MESS!

    There must be an easy way to get this info. Btw, I need to know if I'm in a single or mutiple select scenario because I need to configure the ListView that presents the contacts to allow single or multi selection and to do this I need to know if the app called the pickSingleContactAsync or the pickMultipleContacsAsync method.

    Comments?


    Luis Abreu

    Monday, June 18, 2012 2:11 PM

Answers

  • Luis,

    If you study and understand the sample, you will see events are raised based on the single or multi select option.  You can use those events to manage the selection of the UI.

    In particular you will get the 'contactremoved' event. 

    You should not go through all of this painful stuff.  Please checkout how the sample handles these scenarios.

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, July 03, 2012 6:48 PM
    Moderator

All replies

  • Luis,

    I am confused why you are doing this since the ContactPickerUI allows you to specify if you want to do single or multi selection and the UI handles that all for you.

    Can you provide more info or a sample?

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, June 19, 2012 6:32 PM
    Moderator
  • Jeff. the problem is not adding contacts to the basket. It's the UI.

    my implementation of the contract uses a ListView to allow the user to pick the contacts my app has and this means it  must be configured to allow single or multi select. unfortunately, the contactpickerui doesn't have any property that I can use to get this info. Here's the markup i'm using in my startup page for the contact contract implementation:

    <!DOCTYPE html>
    <html>
        <head>
            <title></title>
            <!-- WinJS references -->
            <link href="//Microsoft.WinJS.1.0.RC/css/ui-light.css" rel="stylesheet">
            <script src="//Microsoft.WinJS.1.0.RC/js/base.js"></script>
            <script src="//Microsoft.WinJS.1.0.RC/js/ui.js"></script>

            <!-- contactos references -->
            <link href="/css/default.css" rel="stylesheet">
            <link rel="stylesheet" type="text/css" href="css/contactos.css" />
            <script src="/js/contactos.js"></script>
        </head>
        <body>
            <div id="headerTemplate" 
               data-win-control="WinJS.Binding.Template">
              <div data-win-bind="innerText: cabecalho" 
               class="win-contentTitle header">
              </div>
            </div>
            <div id="textAlbumTrackTemplate" data-win-control="WinJS.Binding.Template">
                <div class="textAlbumTrack">
                    <h2 class="textAlbumTrackNumber" data-win-bind="innerText: nome"></h2>
                    <h3 class="textAlbumTrackTitle" data-win-bind="innerText: email"></h3>
                </div>
            </div>
            <div id="list" data-win-control="WinJS.UI.ListView"
             data-win-options="{ 
                itemTemplate: textAlbumTrackTemplate,
                itemDataSource: Livro.grupos.dataSource, 
                tapBehavior: 'toggleSelect',
                layout:{type: WinJS.UI.GridLayout, groupHeaderPosition: 'left'},
                groupDataSource: Livro.grupos.groups.dataSource, 
                groupHeaderTemplate: headerTemplate}">
            </div>

        </body>
    </html>

    When the app is loaded, the listview is bound to an internal contact collection and the problem is knowing if the listview should allow single or multiple selection.

    in other words, wHat I need to do is sync the UI with the current behavior (was the contact dialog opened with pickSingle or pickMultiple) and change the number of items that can be selected with the listview. In the previous release, I was adding 2 items during the activated event and checking for their existence 500ms after that. if the two were there, then the user wanted to select more than one item. if not, then the user  only wanted to pick one item. Now, even this horrible workaround won't work because adding the contacts during the activated ends up generating an exception

    Do you understand what I'm trying to do? 

    thanks again.


    Luis Abreu

    Tuesday, June 19, 2012 6:52 PM
  • Jeff, any thoughts?

    If there's an alternate way of doing what I need, please let me know. as is, I think this is a tremendous limitation for someone that wants to implement the contact picker contract.


    Luis Abreu

    Tuesday, July 03, 2012 9:06 AM
  • Luis,

    If you study and understand the sample, you will see events are raised based on the single or multi select option.  You can use those events to manage the selection of the UI.

    In particular you will get the 'contactremoved' event. 

    You should not go through all of this painful stuff.  Please checkout how the sample handles these scenarios.

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, July 03, 2012 6:48 PM
    Moderator
  • Jeff, 

    I'm already handling the contactremoved event to remove the selected item from the list.

    I've already gave a detailed description of the problem in this forum and I've explained why things aren't so easy when you use the listview control: http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/bad11d89-c5c6-451d-8c69-da16d5b3c927

    Unlike the sample you mentioned, I'm using the listview control (not checkboxes). This makes a huge difference. I have a challenge for you: can you port the sample you've mentioned so that it uses a listview control instead of checkboxes? 

    thanks


    Luis Abreu

    Tuesday, July 03, 2012 11:25 PM
  • Jeff,

    You're right: there is a way to solve it, but the code is not as linear as it should be.

    sorry for wasting your time and thanks for pointing me in the right direction.


    Luis Abreu

    Friday, July 06, 2012 12:13 PM