CIS 136 Building Mobile Apps

Slides:



Advertisements
Similar presentations
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
Advertisements

JSON Valery Ivanov.
Introduction CIS 136 Building Mobile Apps 1. What did we do Software review 2.
Figure 1. Hit analysis in 2002 of database-driven web applications Hits by Category in 2002 N = 73,873 Results Reporting 27% GME 26% Research 20% Bed Availability.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
1 Agenda Views Pages Web Parts Navigation Office Wrap-Up.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Beginner Session #1 UNCLASSIFIED Shaunya Murrill/IMCOM, 1 of 24 eArmy Family Messaging System Webinar Training Webinar Training.
User Interface Design using jQuery Mobile CIS 136 Building Mobile Apps 1.
Phonegap Bridge – Telephony CIS 136 Building Mobile Apps 1.
Part 06 – A More Complex Data Model Entity Framework and MVC NTPCUG Tom Perkins.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
USER PROPERTIES Hiiiii.
PHP meets MySQL.
Microsoft Access Introduction. What Is a Database Suppose you are a school administrator. You need to have information about –Students –Faculty –Staff.
HTML5. HTML5’s overall theme The browser as a rich application platform rich, cross-device user interfaces offline operation capability hardware access.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Basic & Advanced Reporting in TIMSNT ** Part Two **
Phonegap Bridge – Compass API CIS 136 Building Mobile Apps 1.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
DT228/3 Web Development Databases. Querying a database: Partial info Search engines, on-line catalogues often need to allow user to search a database.
Three Layer Architecture Why Bother with the Middle Layer?
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Session Making Queries and Multiple Entry Work for You in Direct Loans (Hands-On) Session 21.
Microsoft Access is a database program to manage sort retrieve group filter for certain records.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
ICM – API Server & Forms Gary Ratcliffe.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
Transportation Agenda 77. Transportation About Columns Each file in a library and item in a list has properties For example, a Word document can have.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Phonegap Bridge –Geolocation and Google maps CIS 136 Building Mobile Apps 1.
Access Test Questions Test Date: 05/05/16. Chapter 1 (Lynda.com) Question 1 An access database uses five main components (database objects). Which is.
Acess Test Questions. Chapter 1 (Lynda.com) Question 1 An access database uses five main components (database objects). Which is not one of them? Tables.
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
Phonegap Bridge – Storage CIS 136 Building Mobile Apps 1.
1 Terminal Management System Usage Overview Document Version 1.1.
JavaScript, Sixth Edition
Receiving form Variables
NFIRS Data Entry Browser Interface (DEBI) nfirs. fema
Writing Basic SQL SELECT Statements
Microsoft Office Access 2010 Lab 2
CIS 136 Building Mobile Apps
The EBSCOhost iPhone Application
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
CIS 136 Building Mobile Apps
JDBC.
Geolocation using Google maps
CIS 136 Building Mobile Apps
>> PHP: Form Processing
ISC440: Web Programming 2 Server-side Scripting PHP 3
Social Media And Global Computing Managing MVC with Model Validation
CIS 136 Building Mobile Apps
The EBSCOhost iPhone Application
NFIRS Data Entry Browser Interface (DEBI) nfirs. fema
jQuery form submission
CIS 136 Building Mobile Apps
Phonegap Bridge Configuration file
CIS 136 Building Mobile Apps
CIS 136 Building Mobile Apps
NFIRS Data Entry Browser Interface (DEBI) nfirs. fema
Integrating REST API and SQL Server JSON Functions
NFIRS Data Entry Browser Interface (DEBI) nfirs. fema
CIS 136 Building Mobile Apps
Access Test Questions Test Date: 05/05/16.
NFIRS Data Entry Browser Interface (DEBI) nfirs. fema
PHP and JSON Topics Review JSON.
NFIRS Data Entry Browser Interface (DEBI) nfirs. fema
Presentation transcript:

CIS 136 Building Mobile Apps Contacts CIS 136 Building Mobile Apps

Contacts API provides an interface that can be used to create, locate, edit, copy and delete contacts Interfaces with the native Contacts database provided by the mobile platform

Creating a contact Synchronous API call, as it has no callback functions Create method creates an empty object Syntax: var contact = navigator.contacts.create([parameters]); Next steps are: to populate the properties of the object with contact data save the object to the Contacts’ application database

Example - Creating a contact <script> $(document).on("deviceready", onDeviceReady); function onDeviceReady() { var myContact = navigator.contacts.create({"displayName": "Test User"}); myContact.note = "This contact has a note."; myContact.save(onSuccess,onError) } </script> </head> <body> <h1>Example</h1> <p>Create Contact</p> </body> </html>

Contact data example using JSON string var myContact = navigator.contacts.create({ “FullName”: “Michael Smith”, “LastName”: “Smith”, “Firstname”: “Michael”, “EMailAddress”: mSmith@yahoo.com, “OfficePhone:” : “333-212-5555”, “MobilePhone”: “333-212-5556” });

Finding a contact Asynchronous method that queries the device contacts database and returns an array of Contacts as objects Syntax: navigator.contacts.find(contactFields, contactSuccess, contactError, contactFindOptions); Parameters contactFields: Required. Contact fields to use as a search qualifier. The resulting Contact object only features values for these fields. contactSuccess: Required. Success callback function invoked with the contacts returned from the database. Returns an Array contactError: Optional. Error callback function, invoked when an error occurs. contactFindOptions: Optional. Search options to filter contacts.

Contact Error Returned through the ContactError callback function Properties code: One of the predefined error codes listed below. Constants ContactError.UNKNOWN_ERROR ContactError.INVALID_ARGUMENT_ERROR ContactError.TIMEOUT_ERROR ContactError.PENDING_OPERATION_ERROR ContactError.IO_ERROR ContactError.NOT_SUPPORTED_ERROR ContactError.PERMISSION_DENIED_ERROR

contactFindOptions properties that can be used to filter the results of a contacts.find operation filter: The search string used to filter contacts. (Default: "") multiple: Determines if the find operation returns multiple contacts. (Boolean) (Default: false)

Finding contacts - Example 1 // specify contact search criteria var options = new ContactFindOptions(); options.filter=""; // empty search string returns all contacts options.multiple=true; // return multiple results fieldsToReturn = {"displayName“}; // return contact.displayName field // find contacts navigator.contacts.find(fieldsToReturn, onSuccess, onError, options); // success callback function onSuccess(contacts) { for (var i=0; i<contacts.length; i++) { alert(contacts[i].displayName); } }; // error callback function onError(contactError) { alert('onError!');

Finding contacts - Example 2 $(document).on("deviceready", onDeviceReady); function onDeviceReady() { // find all contacts with 'Bob' in any name field var options = new ContactFindOptions(); options.filter = "Bob"; var fieldsToReturn = ["displayName", "name"]; navigator.contacts.find(fields,ToReturn onSuccess, onError, options); } function onSuccess(contacts) { for (var i = 0; i < contacts.length; i++) { console.log("Display Name = " + contacts[i].displayName); function onError(contactError) { alert('onError!');

Look at your contacts on your mobile device what fields do you see on your device?

Contact Objects Objects Contact ContactName ContactField ContactAddress ContactOrganization ContactFindOptions ContactError

Contact Object methods clone() Returns a new Contact object that is a deep copy of the calling object, with the id property set to null. remove() Removes the contact from the device contacts database, otherwise executes an error callback with a ContactError object. save() Saves a new contact to the device contacts database, or updates an existing contact if a contact with the same id already exists.

Contact object properties describe a contact, such as a user's personal or business contact id A unique identifier for the contact displayName The name of the contact name (object) – defines different components of the name (i.e. given name, family name, middle name, etc.) nickname Casual name phoneNumbers (array) –phone numbers Emails (array) email addresses Addresses (array) – physical addresses – home, business, etc.

Contact properties (continued) ims (array) – instant messaging addresses Organizations (array) – a list of the organizations the contact is associated with Birthday Contacts date of birth note Variable used for text-based notes photos (array) – photos of the contact categories (array) user-defined categories associated with the contacts (i.e. friend, family, etc) urls (array) – web addresses associated with the contact

Name Object defines different components of the name (i. e Name Object defines different components of the name (i.e. given name, family name, middle name, etc.) Includes string values: formatted: contacts complete name givenName: family name middleName: middle name honorificPrefix: Dr. Mrs. Mr. etc honorificSuffix: Jr, III, PhD, etc.

Example var options = new ContactFindOptions(); options.filter = ""; fieldsToShow= ["displayName", "name"]; navigator.contacts.find(fieldsToShow, onSuccess, onError, options); function onSuccess(contacts) { for (var i = 0; i < contacts.length; i++) { alert("Formatted: " + contacts[i].name.formatted + "\n" + "Family Name: " + contacts[i].name.familyName + "\n" + "Given Name: " + contacts[i].name.givenName + "\n" + "Middle Name: " + contacts[i].name.middleName + "\n" + "Suffix: " + contacts[i].name.honorificSuffix + "\n" + "Prefix: " + contacts[i].name.honorificSuffix); } }; function onError(contactError) { alert('onError!');

Addresses (array) – physical addresses – home, business, etc. Two-dimensional array of contact address objects with these values pref: Boolean value that defines if the entry is the default address for the contact type: String defining the address type (home/work) formatted: Full address formatted for display streetAddress: Full street address locality: city region: state postalCode: Zip code country Country associated with address

Example function onSuccess(contacts) { // find all contacts var options = new ContactFindOptions(); options.filter = ""; var fieldsToShow = ["displayName", "addresses"]; navigator.contacts.find(fieldsToShow, onSuccess, onError, options); function onSuccess(contacts) { for (var i = 0; i < contacts.length; i++) { for (var j = 0; j < contacts[i].addresses.length; j++) { alert("Pref: " + contacts[i].addresses[j].pref + "\n" + "Type: “ + contacts[i].addresses[j].type + "\n" + "Formatted: " + contacts[i].addresses[j].formatted + "\n" + "Street Address: " + contacts[i].addresses[j].streetAddress + "\n" + "Locality: " + contacts[i].addresses[j].locality + "\n" + "Region: " + contacts[i].addresses[j].region + "\n" + "Postal Code: " + contacts[i].addresses[j].postalCode + "\n" + "Country: " + contacts[i].addresses[j].country); } }; function onError(contactError) { alert('onError!');

Two-dimensional array of organization objects with these values Organizations (array) – a list of the organizations the contact is associated with Two-dimensional array of organization objects with these values pref: Boolean value that defines if the entry is the preferred or default organization for the contact type: String defining the type of organization (home/work) name: name of the organization department: department where the contact works title: Contacts title in the organizations

Example – 2 dimensional function onSuccess(contacts) { for (var i = 0; i < contacts.length; i++) { for (var j = 0; j < contacts[i].organizations.length; j++) { alert("Pref: " + contacts[i].organizations[j].pref + "\n" + "Type: " + contacts[i].organizations[j].type + "\n" + "Name: " + contacts[i].organizations[j].name + "\n" + "Department: " + contacts[i].organizations[j].department + "\n" + "Title: " + contacts[i].organizations[j].title); } }; function onError(contactError) { alert('onError!'); var options = new ContactFindOptions(); options.filter = ""; filter = ["displayName", "organizations"]; navigator.contacts.find(filter, onSuccess, onError, options);

Phones, emails, and ims Two-dimensional array of objects with these values pref: Boolean value that defines if the entry is the default value type: String defining the type of value (home/work) value: Contact value such as phone number or email address

Example var contact = navigator.contacts.create(); // store contact phone numbers in ContactField[] var phoneNumbers = []; phoneNumbers[0] = new ContactField('work', '212-555-1234', false); phoneNumbers[1] = new ContactField('mobile', '917-555-5432', true); phoneNumbers[2] = new ContactField('home', '203-555-7890', false); contact.phoneNumbers = phoneNumbers; // save the contact contact.save();

More Information https://github.com/apache/cordova-plugin-contacts