Using Places API (Part III: WRT issues and App demo)

In this post I will talk mainly about the part that gave me
the worsts headaches when coding the application:  Platform Services 2.0.
While I was coding the place search and selection (using Places API) everything
was more or less progressing smoothly, but when you need to access the phone
things get a bit messy.

When you start programming using Nokia WDE, one of the first
things you notice is that there is no way of debugging Symbian WRT applications
when using the simulator.
For example: you can’t put breakpoints to see the variable values. So you have
to debug “old style” using alerts and your own var_dump functions.

While you don’t use the phone services, you can just run
your webApp on your web browser and debug it as any other. But this comes to an
end the second you start using in your code the Platform Services functions to
access the phone.

So to debug I often use this var_dump function that I found
somewhere online. I just changed a little bit the code to suit my needs:

function inspect(obj, maxLevels, level){

    var
str = , type, msg;
    //
Start Input Validations
    //
Don’t touch, we start iterating at level zero

    if
(level == null)
        level
= 0;
 
  
// At least you want to show the first level

    if
(maxLevels == null)
        maxLevels
= 1;
    if
(maxLevels < 1)
        return ‘<span
style="color:red;">Error: Levels number must be >
0</span>’
;
    //
We start with a non null object
    if
(obj == null)
        return
‘<span style="color:red;">Error:
Object <b>NULL</b></span>’
;
    //
End Input Validations
   
    // Each
Iteration must be indented
    str
+= ‘<ul
style="list-style:circle;padding:15px;">’
;

    // Start
iterations for all objects in obj
    for
(property in obj) {
        try {

            // Show
"property" and "type property"
            type = typeof(obj[property]);

            str
+= ‘<li
>(‘
+ type
+ ‘) ‘ + property +
            ((obj[property] == null) ? (‘: <b>null</b>’) : ()) + ((type != ‘object’) ? (‘: ‘+obj[property]) : ()) +
            ‘</li>’;

            // We keep
iterating if this property is an Object, non null
            // and we are inside the required number of levels
            if ((type == ‘object’) && (obj[property] != null) && (level + 1 < maxLevels))

                str
+= inspect(obj[property], maxLevels, level + 1);
        }

        catch
(err) {
            // Is there some properties in obj we can’t access? Print
it red.
            if (typeof(err) == ‘string’)

                msg
= err;
            else
                if (err.message)
                    msg = err.message;
                else
                    if (err.description)
                        msg = err.description;
                    else

                        msg = ‘Unknown’;

           str
+= ‘<li><span
style="color:red;">(Error) ‘
+
property + ‘: ‘ + msg + ‘</span></li>’;

        }

    }   

    // Close indent
    str
+= ‘</ul>’;   
    return
str;
}

 

I had some other issues
with the Platform Services (2.0  version),
the most important being that the Contacts API doesn’t seem to work at all in
the latest version of Symbian (Symbian Anna). 

For those who also
encounter issues with PS 2.0, it seems the official recommendation is to switch
to the old version, the PS 1.0 (as
said here
). Unfortunately it didn’t work in my case, just loading the 1.0 Contacts
API instantly crashed the application.

For that reason I
developed a version of the application getting the Friends list from the
outgoing calls log, instead of the phone contacts.

I put the code here:

Contacts version

 

//Gets the contacts list using
platformservices 2.0
function showContacts()
{
    try
{
       cal
= nokia.device.load("contacts");    
       try{
              if (typeof contacts
== "undefined") nokia.device.load("contacts");
              var
transactionID =
cal.getContacts(result_contacts,null,null,errorCB);          
      
}
       catch(e){ errorCB(e); extraDebug(e);}   
   
}
    catch
(e) {alert("cannot load contacts service"+extraDebug(e));}
}

//Success callback function for
the getContacts call
function result_contacts(outPut)
{
    var
entry = null;   
    try
{
        eligible_contacts
= new
Array();
        while ((entry = outPut.next()) != null) {
            //I keep the contacts in a list.
            eligible_contacts.push(entry);
        }
        selected_contacts
= new
Array();
        showEntryList(eligible_contacts, false, false);      
    }

    catch(err){extraDebug(err);}   
}

Call Logs version

 

//Gets the contacts using the log of outgoing calls, currently without Date
restriction.
function callLog(){
    if
(eligible_contacts
=== null) {
              alert("using outgoing calls log to fill the friends
list"
);//we
only alert the first time
              try {

                     var
commlog = nokia.device.load("commlog");
                     // Retrieves the specified number of logs.                          
                     var transactionId
= commlog.getList(showLogContatcs, {
                           type: "CALL",
                           flag: "OUTGOING"
                     }, errorCB);
             
}
              catch (e) {alert(e.toString());}
      
}     
}

//callback function for commlog, it fills the eligible_friends list with
the numbers retrived from your call log.
function showLogContatcs(outPut)
{
       var
entry=null;
       var
log;
       var
i=-1; // used for the id of the entry.
       try
{
        eligible_contacts
= new
Array();
        while ((log = outPut.next()) != null) {
            entry = new Object();
                     entry.id=i;
                     entry.tel= new Object();
                     entry.tel.mobile=log.phoneNumber;
                     entry.name= new Object();
                     entry.name.first=log.contactName;
       //I keep
the contacts in a list only if they are not repeated. In that case I keep the
one with name.
                     keepLogEntry(entry);      

                     i–;
        }

        selected_contacts
= new
Array();
        showEntryList(eligible_contacts, false, false);
    }

    catch(err){ extraDebug(err);}
}

 

Another bug appeared using the 2.0 Contacts API (in Symbian
older than Anna),  when iterating through
the results, but as it might be due to the phone I was using I will not dwell
into details, if you are interested look at this post
for more information.

However, after all the headaches were solved I finally had
the application up and running. Here I leave you some images to see how it
looks:

IMAGE 1: Here you can search for a place, either by category (like
restaurants or shops) or directly by name in the searchbar. Assume that we clicked the restaurants category.

IMAGE 2: After that, you look in the results and choose a place of
your liking, by clicking on it.

IMAGE 3: Here you take a detailed look at the place
that you chose and click on the "meet" icon to select this place as the
meeting point.

IMAGE 4: Then you choose the people that will be attending the meeting
(form your contacts  list or call log
depending on the version).

IMAGE 5: You pick a time for the meeting. And press the “Create
Meeting” button. Then the application will create an event in your phone calendar, also
an iCalendar file that will be attached to the MMS message sent to all the
numbers you previously choose.

IMAGE 6: Finally if all went well you’ll see a summary screen like
this.