My real experience with building mobile applications started when Apple moved from a pure web application model for the iPhone to the App Store model, which effectively resulted in a fundamental shift in the mobile app landscape. For one thing, we started calling them apps. My background had always been web centric, and so the previously HTML5 based solutions made a lot of sense, and even after native development became and option and I started working with Objective-C – the speed and ease of building web-based applications was extremely appealing.
However – there were two use cases that commonly would occur when designing enterprise apps that usually meant using native code: the camera and secure offline storage. When it comes the former, I think it is just an aftereffect of an entire populous which is used to having a camera always so close at hand. Where previously the idea of can I associate this data point with an image might seem overly burdensome, it now belongs will within the mobile citizen’s Bill of Rights. The latter, storing data offline, was a failure of HTML5 caused by a complete lack of a security model and competing protocols to provide a singular solution.
Naturally, these technical problems caught the attention of erstwhile hackers seeking to solve them. Out of similar projects, I had always kept an eye on PhoneGap and frequently tested it during the early phases of development. It’s been several cycles since then, and PhoneGap is now a very mature open source product – which is why we include it with the Salesforce Mobile SDK.
So your first step, if you haven’t already done it, is to install the Salesforce Mobile SDK, part of the Salesforce Platform Mobile Services. The SDK includes not only Cordova, but plugins which include additional features like handling the OAuth login flow. Once installed, you can build both native applications (designed for Java or Objective-C) or hybrid ones. See the Gettting Started for the Mobile SDK (iOS or Android) for more information.
Accessing the Camera
Now with the two parts of Cordova able to communicate, you can start accessing native functionality. To have the browser pull up the camera UI and hand back the resulting image, simply use:
SmartStore uses a schema-less, NoSQL style structure called soups. The term is a bit of jargon leftover from the original Newton project. A soup basically has two bits to every row: An index object which defines what can be searched against, and a object storing the actual data. So first you define your index structure:
And then you can register your soup:
Giving a callback function for success and error. Since we don’t have SQL, you create query objects to search against records. For instance:
Builds a query with a like operator that will search for records containing Fred anywhere in the name, then queries the soup and hands the first page off to render. With query objects, you can set the number of records to a page (20 in our case) to structure the results into a series of arrays.
To learn more about using SmartStore, see the recently published wiki article.
Seeing it in action