Whats the Purpose of This Book

In 2001, I set up a web site called .NET 247 (www.dotnet247.com ) that at the time achieved some success in the community that had sprung up around Microsoft's new software development toolset. The premise of the site was to help me as a developer migrate my knowledge from pre-.NET technologies (Win32, MFC, classic ASP, etc.) over to .NET. I found it frustrating that spinning up a thread or opening a file would be a few seconds' work prior to .NET, but in .NET it took hours of research. With...

Querying the Feed

Let's look now at parsing the XML we got back from the server. First of all, let's stub our ODataServiceProxy class. This is going to extend ServiceProxy and will implement some generic support of OData-based data. Although we only work with one OData service, it's not unusual to work with several in a production application, and therefore it's worth breaking out functionality into a base class by way of illustration. Here's ODataServiceProxy package import java.util.* import org.w3c.dom.*...

The Users Service

The users service is a RESTful web service that provides a capability to log on a user. (This book deals only with logging users on however, the service is capable of other functions, including registering users.) It's important to familiarize yourself with how the service works, as it will aid in understanding the flow of the applications that we will build in later sections. A RESTful web service is a service that is based on the principle of REST, which stands for Representational State...

Building the Xml Helper Class

In Chapter 4, we used the BootFX HttpHelper class to smooth over the intricacies of making HTTP requests. We also used the BootFX class XmlHelper to make working with XML data easier. Android uses the regular XML DOM manipulation API found in the com.w3c.dom namespace. Although extremely fiddly, this API provides a very powerful set of functions to reading, changing XML documents in a safe and ultimately maintainable fashion. The full version of the API also allows you to create documents, but...

Installing Mono Touch

MonoTouch is a commercial product, and as such you can either download an evaluation version or install a full version. Mono itself is open-source. MonoTouch runs only on Mac, which is understandable, seeing as you still need the Interface Builder component of Xcode 3 to build the UI and also need the execution environment and libraries that Xcode itself needs to build and run iOS applications. NOTE For those that have come to iOS development fresh on Xcode v4, in previous versions the user...

UIApplication app [UIApplication sharedApplication

self.view self.view.bounds.size.width, self.view.bounds.size.height - void viewDidAppear BOOL animated self.view.backgroundColor UIColor groupTableViewBackgroundColor do the base's implementation. super viewDidAppear animated We won't dwell on this code as it's not core to our discussions, but if you run the project again, you will get a more pleasing result, as shown in Figure 9-6. Figure 9-6. The logon form now showing correctly. Figure 9-6. The logon form now showing correctly.

Building the Push Updates Method

We'll start by building the PushUpdates method. There's going to be quite a lot of work here. In this section, we'll first look at the algorithm for detecting changes, and then we'll look at how we physically send changes up. The algorithm for detecting changes looks like this Download the latest set of bookmarks from the server. Walk each change detected on the client and find the matching server item based on the ordinal of the item. If a local change was found and that change can be mapped...

Issuing OData Change Requests

When we needed to create XML documents on Android, we used the XML Pull Library and its XmlSerializer class to manually create the document. You may also recall that my preferred method for building XML documents is to use a DOM approach, such as the XmlDocument class in .NET. However, just as Android does not give us a DOM-style API for creating documents, neither does iOS. Instead we have to use the Libxml2 library, which is an open-source library that is part of Gnome. It essentially works...

Issuing Requests

I won't repeat the discussion from the Android chapter that has a quick look at the OData protocol, but I will repeat the presentation of the XML that we need to issue. This is an example of an OData XML document used to create a bookmark on the server POST services bookmarks.svc Bookmark HTTP 1.1 Host services.multimobiledevelopment.com accept application atom xml content-type application atom xml content-encoding UTF-8 content-length 384 x-amx-apiusername amxmobile x-amx-token...

Wiring Up the Button

If you're used to declaring markup and writing code-behind supporting code for it using Microsoft ASP.NET, like I was before coming to Android, you may well find Android's approach a little clunky There is a lot of manual wiring up and fiddling around to do to make the UI work. When we define user elements within the XML, we give it an ID value. This was done previously with this attribute in the XML The Android Eclipse plugin maintains a special code file called gen lt packageName gt R.java....

Examining the Database with Sqliteman

At this point, we can take an entity type and create a database for it. We might as well do this now, as we have quite a long way to go before we can get some real data into it We haven't yet built the Sync class, but we can start to do this now. We'll start it off by asking it to ensure the database exists, but we won't add the logic to do anything other than that. The Sync class will need access to a Context object so that it can create a DatabaseHelper, which, in turn, will call the...

Including SQLite

Our initial work involves configuring our Xcode project with references to the SQLite library. The first step is to add a new framework to the project. NOTE This process is quite complicated in the Xcode 4 beta that I'm using it's possible that this will be made slightly easier in the production version. Refer to the web site if these steps seem to bear no relation to your edition of Xcode. In the Project Navigator, click on the project entry at the top of the tree. This is the blue box titled...

Creating SBEntity Type Instances

Before we can create instances of SBBookmark and use them, we need to be able to create an instance of SBEntityType that supports it. In more sophisticated ORM layers, it is commonplace to build the metadata up from some sort of decoration in the code e.g., attributes in .NET . In this implementation, we're going to build a class called SBRuntime and have it register the entity type on start. Here's the definition import lt Foundation Foundation.h gt

Building the View Engine

Structurally, the way we're supposed to build iOS applications is to create a single window and then swap views in and out of that window depending on what we want to do. To support this, we're going to have to create our own view engine. The design of the view engine that we'll build here is one that retains a pool of views in memory. When the application requires a view, it'll request one from the pool, creating one if one does not exist or recycling an existing view if it does. This sort of...

Logging On the User

Now that we have obtained a token to use and authenticated the API, we can actually log on the user. We've used the API service so far we're now going to use the Users service. If you click the User Logon link on the test harness, the URL will be rewritten to the following This URL is configured to call the Users REST service. If you replace the USERNAME and PASSWORD placeholders in that string, and assuming you have copied the token into the Token header field, and click Send Request, you'll...